I've used RVM to install the latest stable version of Ruby, however, I can't set it to be the default version. Running which ruby
always returns the path of Ruby installed with MAMP on my system eg /Applications/MAMP/Library/bin/ruby
I've tried various rvm commands with no effect. I'd rather not have to run an rvm use command every time I open my terminal.
I'm using oh-my-zsh and iTerm2 if it makes a difference.
CodePudding user response:
As Dave Newton suggested, this smells like a PATH
issue, but in the case of MAMP, it's also an alias
issue.
If you open ~/.profile
and ~/.zprofile
, in one of them you will probably see these lines:
alias erb='/Applications/MAMP/Library/bin/erb'
alias gem='/Applications/MAMP/Library/bin/gem'
alias irb='/Applications/MAMP/Library/bin/irb'
alias rake='/Applications/MAMP/Library/bin/rake'
alias rdoc='/Applications/MAMP/Library/bin/rdoc'
alias ri='/Applications/MAMP/Library/bin/ri'
alias ruby='/Applications/MAMP/Library/bin/ruby'
alias rails='/Applications/MAMP/Library/bin/rails'
You'll want to remove them all, save the file, then quit and restart iTerm2.
If you don't know how to open and edit dotfiles, read my guide that explains various ways to read and edit dotfiles on a Mac.
If removing those aliases doesn't fix it, then it's a PATH
issue.
For your Mac to know about a command or other executable program, it has to be told where to look for it. It wouldn't be efficient for the computer to search the entire hard drive for the program.
Instead, it looks in a specific list of locations, which are stored in an environment variable called PATH
, separated by a colon. You can view this list by running this command in your terminal:
echo $PATH
When you install new programs, such as Ruby, they might get installed in a location that is not already included in the PATH
. If you don't add this new location to the PATH
, the computer won't know to look for it there, and so it thinks it doesn't exist.
Similarly, if the location of the new program did get added to the PATH
, but you have another location for the same program earlier in the PATH
, then it will always use the first one it finds.
Most Ruby version managers use a script to automatically update the PATH
, and they instruct you to add a line to your shell file to call that script, or they might add it for you. That line should come after any modifications of PATH
.
It's been a while since I've used RVM (I no longer recommend it), but I think it's supposed to automatically add this line to your shell file:
source $HOME/.rvm/scripts/rvm
Assuming you installed RVM properly, here's what I would try:
Open your shell file. It should be
~/.zshrc
if you're using oh-my-zsh.Look for any lines that start with
export PATH=
, and if they mention/Applications/MAMP/Library/bin/ruby
, remove that directory from thePATH
. Also make sure anyPATH
lines come before the lines added by RVM.Quit and restart iTerm2
If you don't see any RVM-related lines in ~/.zshrc
or ~/.zprofile
or ~/.profile
, then RVM was not properly installed.
If you really want to use RVM, try uninstalling and reinstalling it. If all you care about is having a working Ruby environment, I would recommend chruby and ruby-install. You can install them by following my step-by-step guide to install Ruby on Mac.