Blog/github pages

bundle install 시 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 발생

떼루르르 2023. 6. 26. 21:01

새로운 github pages 테마를 적용하기 위해 새로운 테마를 다운받고 bundle install을 하던 도중 에러가 발생.

Gemfile의 내용은 아래와 같은 상황.

source "https://rubygems.org"

gem "dotenv"
gem "github-pages"
gem "jekyll"
gem "jekyll-github-metadata"

bundle install 시 아래와 같은 에러가 발생하였다.

bundle install
Warning: the running version of Bundler (2.1.4) is older than the version that created the lockfile (2.3.14). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.3.14`.
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using concurrent-ruby 1.1.10
Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Using i18n 0.9.5
Using minitest 5.15.0
Using thread_safe 0.3.6
Using tzinfo 1.2.9
Using zeitwerk 2.5.4
Using activesupport 6.0.5
Using public_suffix 4.0.7
Using addressable 2.8.0
Using bundler 2.1.4
Using coffee-script-source 1.11.1
Using execjs 2.8.1
Using coffee-script 2.4.1
Using colorator 1.1.0
Fetching commonmarker 0.23.4


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password:


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password:
Installing commonmarker 0.23.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/private/var/folders/6x/0zv8bqhj3rxgnc4hk038bn2c0000gn/T/bundler20230620-63777-ldy2j5commonmarker-0.23.4/gems/commonmarker-0.23.4/ext/commonmarker
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20230620-63777-1hs36vf.rb
extconf.rb
creating Makefile

current directory:
/private/var/folders/6x/0zv8bqhj3rxgnc4hk038bn2c0000gn/T/bundler20230620-63777-ldy2j5commonmarker-0.23.4/gems/commonmarker-0.23.4/ext/commonmarker
make "DESTDIR=" clean

current directory:
/private/var/folders/6x/0zv8bqhj3rxgnc4hk038bn2c0000gn/T/bundler20230620-63777-ldy2j5commonmarker-0.23.4/gems/commonmarker-0.23.4/ext/commonmarker
make "DESTDIR="
make: *** No rule to make target
`/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22/ruby/config.h',
needed by `arena.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in
/var/folders/6x/0zv8bqhj3rxgnc4hk038bn2c0000gn/T/bundler20230620-63777-ldy2j5commonmarker-0.23.4/gems/commonmarker-0.23.4
for inspection.
Results logged to
/var/folders/6x/0zv8bqhj3rxgnc4hk038bn2c0000gn/T/bundler20230620-63777-ldy2j5commonmarker-0.23.4/extensions/universal-darwin-22/2.6.0/commonmarker-0.23.4/gem_make.out

An error occurred while installing commonmarker (0.23.4), and Bundler cannot continue.
Make sure that `gem install commonmarker -v '0.23.4' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  github-pages was resolved to 226, which depends on
    jekyll-commonmark-ghpages was resolved to 0.2.0, which depends on
      jekyll-commonmark was resolved to 1.4.0, which depends on
        commonmarker

 

아래는 시도해 본 방법들..

이 상태에서 gem install commonmarker -v '0.23.4' 를 해 보라고 해서 실행해 보았다.
그랬는데 아래와 같은 에러가 발생.

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

루비 버전 문제인가 싶어서 현재 루비 버전이 2.6.10p210이므로 2.7.0을 설치하기 위해 rbenv(루비 버전 관리 패키지) 설치 및 현재 프로젝트의 루비 버전 세팅

# 독립적인 루비 버전 관리를 위한 rbenv 설치
rbenv install 2.7.0

# 프로젝트의 루비 버전 선택
rbenv local 2.7.0

 

그런데 이 상태에서 루비 버전을 확인해도 계속 2.6대로 잡는다.
rbenv는 또 2.7.0으로 잡혀 있다.

❯ rbenv versions
  system
  2.6.5
* 2.7.0 (set by /Users/current path/.ruby-version)
  2.7.2
  
  ❯ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin22]

❯ rbenv install --list
2.5.8
2.6.6
2.7.2
jruby-9.2.13.0
maglev-1.0.0
mruby-2.1.2
rbx-5.0
truffleruby-20.3.0
truffleruby+graalvm-20.3.0

 

rbenv rehash로 rbenv shims를 재생성해봐도 동일..

rbenv가 제대로 초기화되지 않았나 해서 rbenv 초기화 진행

쉘 초기화는 다음과 같은 내용을 커맨드라인에 입력한 후, 쉘 초기화 커맨드를 통해 초기화를 진행했다.

# rbenv 초기화
❯ if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

# 쉘 초기화
❯ source ~/.zshrc

 

rbenv 초기화에 필요한 쉘 구문을 분석하면 아래와 같다.

if which rbenv > /dev/null;

  • whici rbenv : rbenv가 시스템 경로 상에 있는지 확인. which는 프로그램의 위치를 출력한다.
  • > /dev/null; : 출력을 /dev/null로 리다이렉션 해 아무것도 출력하지 않게 한다.
  • 두 명령어를 조합하면 rbenv가 시스템에 설치되어있는지 확인할 수 있다.

then

  • if문의 시작. 다음에 오는 명령어는 if문의 조건이 참일 때 실행된다.

eval "$(rbenv init -)"

  • rbenv init - : rbenv를 초기화하는 데 필요한 쉘 명령어들을 출력
  • $(...) : 명령 치환. 얘가 rbenv init - 를 쉘에서 직접 실행되도록 생성
  • eval : 생성된 명령어를 실제로 실행
  • rbenv가 제대로 동작하기 위해 필요한 환경 변수 설정이나 함수 정의 등을 수행

fi

  • if문의 종료

종합하자면, rbenv가 시스템에 설치되어있는 경우 rbenv를 초기화한다는 뜻이다.

위 명령어를 입력했더니 루비 버전이 원하는 버전으로 업그레이드 되었다.

 

이어 gem install commonmarker와 bundle install 모두 정상적으로 수행되었다!