Home Ruby on MacOS - 맥 루비 설치(rbenv)
Post
Cancel

Ruby on MacOS - 맥 루비 설치(rbenv)

Ruby is a programming language , used generally for web development , through a ruby library called rails .

Under macOS , ruby comes pre-installed , and it can be found under : /System/Library/Frameworks/Ruby.framework/Versions/ . Starting macOS Catalina version 10.15 , this is deprecated , and future versions of macOS might not contain ruby by default .

Rbenv is a ruby version manager , which allows to select the ruby version to be active . It also allows to install multiple versions of ruby .

Rbenv installs under the current user directory : ~/.rbenv , and the installed ruby versions , are installed , under : ~/.rbenv/versions

Screen Shot 2022-03-03 at 1.22.30 AM.png

Mac 은 기본적으로 Ruby 를 가지고 있습니다. 하지만 오래된 버전이기 때문에 지금과 맞지 않는 부분이 많습니다. 일반적으로 Homebrew 를 사용해 Ruby 를 설치할 수 있지만, 설치한 Ruby 가 실행 되진 않습니다. 때문에 Rbenv 를 사용해 실제로 사용할 Ruby 버전을 지정해야 합니다.

  • 본 글은 영어로 작성되어 있지만 순서대로 따라하면 문제 없습니다. 다만, Zsh, bash 확인이 필요합니다.

환경

  • MacBook Pro(Intel Core)
  • Monterey OS(Version 12.2.1)
  • git version 2.32.0 (Apple Git-132)

First clone rbenv

Screen Shot 2022-03-03 at 1.22.49 AM.png

using the following command :

1
git clone https://github.com/rbenv/rbenv.git ~/.rbenv

Then execute

Screen Shot 2022-03-03 at 1.23.48 AM.png

1
cd ~/.rbenv && src/configure && make -C src

Screen Shot 2022-03-03 at 1.24.19 AM.png

  • If macOS before catalina , and using bash , execute :
1
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
  • If macOS catalina and after , and using zsh , execute :
1
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc

Execute

Screen Shot 2022-03-03 at 1.24.48 AM.png

1
~/.rbenv/bin/rbenv init

Open Nano editor

Screen Shot 2022-03-03 at 1.26.05 AM.png

  • If bash execute
1
nano ~/.bash_profile

and to autoload rbenv , add :

1
eval "$(rbenv init -)"

ctrl-x , to save and exit.

  • If zsh execute
1
nano ~/.zshrc

and to autoload rbenv , add :

1
eval "$(rbenv init - zsh)"

Ctrl-x , to save and exit.

Execute

Screen Shot 2022-03-03 at 1.26.31 AM.png

  • If the default shell is bash . Usually , this is true for MacOS versions , prior to Catalina .
1
source ~/.bash_profile
  • If the default shell is zsh . Usually this is true , for MacOS Catalina , and after .
1
source ~/.zshrc

Install ruby build , to install ,versions of ruby

Screen Shot 2022-03-03 at 1.26.51 AM.png

1
mkdir -p "$(rbenv root)"/plugins

Screen Shot 2022-03-03 at 1.27.31 AM.png

1
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Verify rbenv has been installed correctly

Screen Shot 2022-03-03 at 1.27.57 AM.png

1
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash

Show the lastest stable releases

1
rbenv install --list

Screen Shot 2022-03-03 at 1.37.34 AM.png

Install Ruby

1
rbenv install <Version>

rbenv rehash

1
rbenv rehash

Version Check(rbenv)

1
rbenv versions

Set global

Screen Shot 2022-03-03 at 1.38.40 AM.png

1
rbenv global <Version>

Version check(Ruby)

Screen Shot 2022-03-03 at 1.38.54 AM.png

1
ruby -v
This post is licensed under CC BY 4.0 by the author.
Trending Tags