CodeingTestPrac

Mac에서 CocoaPods설치 에러해결,rbenv update

sung.hyun.1204 2022. 2. 17. 13:45

 

이글은 2023.03.27일에 수정했으며 1년만에 수정을 했습니다

 

pod 1.12 을 설치 가능합니다.

 

각종 스택 오버플로우와 블로그들을 참고하면서 삽질한 이야기이다.

문제 : sudo 를 이용한 설치를 할때 에러가 지속적으로 나온다.

 

$sudo gem install -n /usr/local/bin cocoapods

 

 

 

다음은 에러 메시지이다. 

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/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 ./siteconf20220217-51941-fej4hb.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
	--with-ffi_c-dir
	--without-ffi_c-dir
	--with-ffi_c-include
	--without-ffi_c-include=${ffi_c-dir}/include
	--with-ffi_c-lib
	--without-ffi_c-lib=${ffi_c-dir}/lib
	--enable-system-libffi
	--disable-system-libffi
	--with-libffi-config
	--without-libffi-config
	--with-pkg-config
	--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
	from extconf.rb:9:in `system_libffi_usable?'
	from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/mkmf.log

 

 

해결방안은 다음과 같다

1. 루비 재 설치

- 강제로 버전을 맞춘다 높은걸로

 

2.환경변수 설정

 

3.cocoapods 설치

 

--------------------------------------------------------------------------------------------------------

1.  루비 재 설치

--------------------------------------------------------------------------------------------------------

 

다음과 같이 순차적으로 터미널에 적어 주자.

 

1.

$ brew install rbenv

 

2. 최신 확인

 

$ rbenv install -l

 

3.1.1 가 최신 이면 최신으로 설치해주자, 2023 년 03월 27일 기준이다.

 

$rbenv install 3.1.1

 

이 다음이 중요하다

 

$ ruby -v

만약 반환 버전이 이전과 같다면 (설치가 안된것 같다면 ) 다음작업을 하자.

 

1. 버전들을 확인하자  현제 사용중인 버전은 * 붙은거라고  보면 된다.

 

$ rbenv versions

 

결과 : 

$ rbenv versions

  system
* 3.0.2 (set by /Users/user/.rbenv/version)
  3.1.1

2. 버전을 System에서 3.1.1 버전으로 변경하자.

$ rbenv global 3.1.1

 

결과 : 


$ rbenv global 3.1.1
$ rbenv versions
  
  system
  3.0.2
* 3.1.1 (set by /Users/user/.rbenv/version)

 

--------------------------------------------------------------------------------------------------------

2.  환경변수 설정

--------------------------------------------------------------------------------------------------------

 

$ nano ~/.zshrc 로 zshrc 파일을  연다.

 

안열리면 

 

$ sudo nano ~/.zshrc

 

nano 는 쉘의 특정 에디터를 불러 오는 키워드라 생각하자. Vi, Vim 뭐든 좋다.

 

zshrc 파일 맨 끝에 eval "$(rbenv init -)" 을 그대로 붙여넣는다.

 

예시 : 

굳이 추가하는 위치가 파일 끝이 아니어도 되긴한다.

 

 

 

nano 에디터 파일을 저장한 뒤 닫는 법 :

^x  눌러서 닫기 

 y 눌러서 저장

마지막에 엔터키 누르면 에디터 수정이 끝난다.

 

닫은 이후 :

 

$ source ~/.zshrc

 

source ~/.zshrc 로 zshrc 파일을 새로 고칩시다.

 

 

마지막으로 확인

$ ruby -v

 

결과 : 

 

--------------------------------------------------------------------------------------------------------

3. cocoapods 설치

--------------------------------------------------------------------------------------------------------

 

3-1. (추천)

$ sudo gem install cocoapods

 

 

3-2.  (비추천)

$brew cleanup -d -v

$ brew install cocoapods

 

3. 확인

pod --version

 

 

결과:

1.12.0

 

 

 

 

 

참고 블로그 : 

https://chc3484.tistory.com/34