Last active
March 14, 2023 01:48
-
-
Save AndrewDongminYoo/ead7033edfb062f20762e3af3c8a9eb8 to your computer and use it in GitHub Desktop.
MacOS에서의 루비버전 셋팅. rbenv와 homebrew를 설치하지 않았다면 다운받은 후에, 이 스크립트를 ".bash_profile", ".zshrc", ".config/fish/config.fish" 등에 불여넣으시면 됩니다. CLI 커맨드로는 `tail -n +3 ruby-version.sh >> ~/.zshrc` 하면 끝!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # this function will check if .ruby-version file exists | |
| function set_ruby() { | |
| if [ -f ".ruby-version" ]; then | |
| version=$(cat .ruby-version) | |
| if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| brew_ruby=$("$HOMEBREW_PREFIX/opt/ruby/bin/ruby" --version) | |
| if [[ $brew_ruby =~ $version ]]; then | |
| echo "💎 now using homebrew version ($version) of Ruby." | |
| export RUBY_PATH="$HOMEBREW_PREFIX/opt/ruby/bin" | |
| return 0 | |
| else | |
| if [ -d "$HOME/.rbenv/versions/$version" ]; then | |
| echo "💎 $version version of ruby was already installed." | |
| else | |
| rbenv install "$version" && rbenv local "$version" && echo "💎 $version version of ruby is ready." | |
| return 0 | |
| fi | |
| export RUBY_PATH="$HOME/.rbenv/versions/$version/bin" | |
| fi | |
| else | |
| echo "💎 .ruby-version file does not contain a valid version number." | |
| fi | |
| fi | |
| } | |
| # so, we can use this function in every opened terminal | |
| set_ruby | |
| # set environment variables for ruby | |
| export PATH="$RUBY_PATH/bin:$PATH" | |
| export LDFLAGS="-L$RUBY_PATH/lib" | |
| export CPPFLAGS="-I$RUBY_PATH/include" | |
| export PKG_CONFIG_PATH="$LDFLAGS/pkgconfig" | |
| OPEN_SSL_DIR=$(brew --prefix openssl@1.1) | |
| export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$OPEN_SSL_DIR" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation.
@rbenv : https://github.com/rbenv/rbenv
@Homebrew : https://github.com/Homebrew/brew