Last active
December 25, 2021 19:36
-
-
Save szurcher/f77a40192c65cc2cc9f3eba8064e2ea9 to your computer and use it in GitHub Desktop.
How to set RVM GEM_HOME and GEM_PATH properly for BASH + TMUX
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
# be sure to change the values below correctly for your system! | |
export GEM_HOME="$HOME/.rvm/gems/ruby-2.4.1" | |
export GEM_PATH="$HOME/.rvm/gems/ruby-2.4.1:$HOME/.rvm/gems/ruby-2.4.1@global" |
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
[ -f "$HOME/.fix_rvm" ] && source "$HOME/.fix_rvm" # read in the necessary GEM_HOME and GEM_PATH values for our default ruby | |
# place the above line just before RVM's: | |
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* |
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
# The short version: | |
# 1) Run 'rvm use default' once in a shell. | |
# 2) echo $GEM_HOME; echo $GEM_PATH | |
# 3) Export these values to the shell in a startup file. | |
# 4) Update the values if you update your default rvm ruby | |
# The very verbose version: | |
# Manually run once: ("$ " at start of a line indicates a command prompt, it is not part of the input to type) | |
$ rvm use default | |
# Next, | |
$ echo $GEM_HOME | |
# example output: /home/user/.rvm/gems/ruby-2.4.1 | |
$ echo $GEM_PATH | |
# example output: /home/user/.rvm/gems/ruby-2.4.1:/home/user/.rvm/gems/ruby-2.4.1@global | |
# RVM should have set these variables appropriately for your default ruby, so we can now steal them to add to our startup scripts | |
# the caveat is we will have to update our scripts if we update our default ruby | |
# in my case, I created a specific file in my home directory (example: /home/user/.fix_rvm) with these lines that export the variables | |
# with the values we got above: | |
# [begin file .fix_rvm] | |
export GEM_HOME="$HOME/.rvm/gems/ruby-2.4.1" | |
export GEM_PATH="$HOME/.rvm/gems/ruby-2.4.1:$HOME/.rvm/gems/ruby-2.4.1@global" | |
# [end file .fix_rvm] | |
# NOTE: $HOME is a variable that equals the '/home/user' part of the examples, the benefit is regardless of your username, it will be | |
# correct where "/home/user" would almost certainly not (except if your username is, in fact, "user", and your system puts your home | |
# directory under /home) | |
# Finally, I add the file to my startup scripts so that the commands in it are executed. I placed them just before RVM does its own | |
# command loading | |
# [snip of my .profile where the command is added] | |
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change. | |
export PATH="$HOME/.rvm/bin:$PATH" | |
[ -f "$HOME/.fix_rvm" ] && source "$HOME/.fix_rvm" # read in the necessary GEM_HOME and GEM_PATH values for our default ruby | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* | |
# [end snip] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For bonus nerd points, short of hacking on rvm itself, you could make a shell function wrapper that updates the file along with running the necessary rvm command(s) to switch the default. I do not feel the need to earn bonus nerd points.