ILoveBaymax
ILoveBaymax

Reputation: 267

How to have ruby 2.3.1 as a default version

I am an absolute beginner of ruby on rails and even web development.

I use Mac OS(El captain 10.11.3)

I would like to ask you how I can use ruby 2.3.1 anytime I would like to develop my project. It seems like that I can use ruby 2.3.1 for good. (Below is the version I would like to use)

ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

This may sound odd, but whenever I get my terminal closed, the version of ruby in my laptop goes back to

ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]

So when I try to develop my project, I always do this

source ~/.bash_profile

The above command allows me to use ruby 2.3.1.

What I want to do is not to put the command "source ~/.bash_profile" when I open my ruby project.

Has anyone encountered any similar problem before? If you have, please leave your comments below. English is not my first language, so if this post does not make sense or you need more information, please let me know as well

Any advice would be appreciated! Thanks in advance!

Upvotes: 0

Views: 2994

Answers (4)

Jigar Bhatt
Jigar Bhatt

Reputation: 4650

Simple write following command in your console

rvm --default use 2.3.1

Upvotes: 1

arjabbar
arjabbar

Reputation: 6404

It seems like you have multiple versions of ruby installed on your machine. In order to easily maintain apps using multiple versions or ruby I would suggest that you look into installing rbenv.

In your situation, there's a system version of ruby, which is 2.0.0 which is already included in your PATH environment variable upon system startup. It seems that you are changing your PATH to include the new version of ruby in your .bash_profile, but that script only gets ran when you open up the terminal. If you start applications outside of your terminal, then they will not get the same environment variables that you set inside of your .bash_profile.

Basically, every program that you start from your Bash terminal will be a child process of the Bash terminal process. And because it is a child process, it will receive all the same environment variables as the parent process. When you start a program from your desktop environment, then it will not be a child process of Bash, so it will not have those environment variables.

I suggest you just install rbenv or rvm to manage ruby versions. If you want to manage your environment variables for windowed applications started from the desktop, then I would follow the answers posted here.

Upvotes: 0

John
John

Reputation: 1963

Use a ruby version manager. Such as RVM rbenv. It makes switching very easy.

Upvotes: 0

Navin
Navin

Reputation: 924

If you are using rvm then try this,

rvm --default use 2.3.1p112

Upvotes: 3

Related Questions