开发者

Default ruby version in Mac Snow Leopard

开发者 https://www.devze.com 2023-01-23 12:20 出处:网络
I updated my ruby version to 1.9.2 but when I start up the terminal and run ruby -v it show 1.8.7. The only way I can switch to ruby 1.9.2 is by writing source ~/.profile in the terminal.

I updated my ruby version to 1.9.2 but when I start up the terminal and run ruby -v it show 1.8.7.

The only way I can switch to ruby 1.9.2 is by writing source ~/.profile in the terminal.

开发者_如何学JAVAHow can I make 1.9.2 the default ruby version?


If you installed a new Ruby without using RVM it's important to modify your PATH to allow the system to find it. You'll need to make sure that /usr/local/bin is before /usr/bin in your path. You can check by typing echo $PATH at the command line. If it isn't then add a line to your ~/.bash_profile like:

export PATH=/usr/local/bin:$PATH

That way the OS will search the locally-installed apps before the default system-installed apps. Open a new shell and type which ruby and you should see your system is pointing to the new Ruby. Keeping read though, because understanding how your session initializes is important for setting up your development environment.

When using BASH as your shell, you can have ~/.bashrc, ~/.bash_profile and/or ~/.profile as start-up scripts to initialize your session. Depending on how the shell is started one of those will be called but usually it's ~/.bash_profile followed by ~/.profile.

To make my life simpler normally I put my start up commands in ~/.bash_profile then point ~/.bashrc to it by putting a source statement in it. So, put your RVM initialization command in ~/.bash_profile and make sure that ~/.bashrc points to it, which it should do by default.

Do a man bash from the command-line and read about it in the INVOCATION section or read about it in Wikipedia's BASH section.

For reference, this is the command Wayne says to put as the LAST executable in the file to get RVM initialized:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

RVM's Installation page has more information about this in the "Post Install" and "Troubleshooting your Install" sections.

RVM works really well, and the set up is easy. The biggest problem I've seen is people not getting the RVM invocation in their start-up script or having a buggered-up script that kept the command from being executed. If you can't get it to work then you might consider putting your startup scripts into a pastie page or adding it to your original question, and letting us see what's up.


Put the "source ~/.profile" in your ".bashrc" file so it runs every time a shell is created.

Or alternatively, use RVM. It makes having several coexisting Rubies a breeze.


If 'source ~/.profile' is working, try just quitting and restarting terminal, or just opening a new terminal window. If you are using the same terminal window as you used to update ruby, it still has your old profile. You probably do not want to source your profile from .bashrc.. if your alias is being changed after you run .bashrc, strange things could end up happening to your $PATH variable, as you will be altering it twice.

If the relevant line in your .profile is aliasing the 'ruby' command, it should work. I just altered my ruby command in profile to 'alias ruby="ruby1.9" and opened a new terminal. ruby -v now returns ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号