I am running my rails app from a virtualbox build by vagrant using puppet scripts. Every time I login to the box, I have the following problem:
When I run rvm list one of the things it lists is the following:
=* ruby-2.1.1
But when I try to run rails console, it tells me I need to install missing gems. When I run rvm use default, and then run rails console, it works. Why is the default and current setting in rvm not working--why do I have to go to the extra step of also telling rvm which ruby version to use?
Note: I do have a .ruby-version file with 2.1.1 in it. I'm using rvm version 1.25.25
Because you have to tell rvm which version to use.
In earlier version of rvm we have to define .rvmrc file which mention which ruby and gemset to use.
In recent version of rvm we have to define .ruby-version file with ruby version in it and .ruby-gemset file with the name of gemset.
If you just want a quick solution then in your rails directory make a .ruby-version file with content 2.1.1
correct syntax is:
rvm --default use ruby-2.1.1#global
This command sets ruby to selected default permanently. All new terminals will use your default Ruby. Also you don't mention anything about gemset, so I presume global would exist if you didn't mess up your setup.
This solved it:
I added rvm use --default to the machine's ~/.bashrc file.
Related
I first used rbenv to install ruby ver 2.2 and Rails ver 4.2 on Linux CentOS 7, then used rvm to install ruby ver 2.4 and rails ver 5.2. Is there a way to switch between these easily or do they both have to be installed using the same method for this to work?
Better you can use rvm. Rvm is the better tool to switch between many versions with the command
rvm use ruby-2.5.1 or rvm use 2.5.1
For list out all rvm just use
rvm list
within rvm, you can manage the versions nicely no need of rbenv here.
I prefer RVM, it's easy to switch between version, also you can use multiple rails version for that ruby easily
install rvm, install ruby and create a gemset with rvm use 2.4#rails_5_2 --create will create a gemset with name rails_5_2
for switching between versions. I use .ruby-version and .ruby-gemset files in my project so i don't need to specify version all the time
in the .ruby-version file write the ruby version
2.4
and inside ruby-gemset write gemset name
rails_5_2
so whenever you will run the project it takes ruby and rails version from there
you can create this two file manually or you can run this command in terminal from your application directory which will create this two files
rvm --ruby-version use 2.4#rails_5_2
I fixed this by removing RVM and installing the newer versions with rbenv instead. Having both versions installed with the same method allowed it to be easy to switch when needed. The shims automatically use the correct Rails versions for each project respectively. As far as I can tell, the Rails versions are locked in with whichever one you started the project with. You can switch the Ruby version for each project by using:
# rbenv local 2.4.1
I chose rbenv over rvm because I read several articles of people praising rbenv's lightweight approach and ease of use over rvm.
NOTE: the "#" character is the beginning of the command line in Linux CentOS 7, NOT a character that you type in.
EDIT: Thank you guys for the recommendations, though. It got me to look more into using rbenv vs. rvm.
Yesterday I installed ruby and rails using rvm in ubuntu 12.04 and it is working fine and also created a sample application.But today when i run
ruby -v
it is showing like
The program 'ruby' can be found in the following packages:
ruby1.8
ruby1.9.1
Try: apt-get install
You probably forgot the latest step when installing RVM. It is mentioned at the end of the install process but easily overlooked. It boils down to this:
Make sure you have the following lines at the bottom of ~/.bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
source "$HOME/.rvm/scripts/rvm"
This will load RVM right after you open a new shell. Without it, RVM is not 'activated' and when you type ruby it will use the version installed through your OS package manager and not the version installed through RVM.
Run rvm list. If it shows rubies then everything is ok and go to step 2.(if any problems then try reinstall rvm)(if it shows empty rubies list, then install ruby using rvm again(rvm install 2.1.1)
Specify current rvm ruby by one of the following ways:
Specify ruby version manually by running rvm use 2.1.1 for ruby2.1.1. This way you have to call this command every time you open a terminal (see next ways if this doesn't suit you)
Set default ruby version. See here.
Use .rvmrc file in any directory(see here how) to make rvm change ruby version when you open this directory.
Probably that is your case.
In addition to zwipple's answer, if you can also load rvm for once using following command:
source ~/.rvm/scripts/rvm
ruby -v
=> #your ruby version
Before I installed MySQL and restart my computer, my RVM works well.
If I type
rvm gemset use rails
It will show:
Using ruby-1.9.3-p194 with gemset rails
and then I type:
rvm gemset name
It shows:
rails
which is correct.
However, after I restart my computer, something strange happens.
Firstly, the system cannot find the command 'rvm', so I modified by ~/.bash_profile:
export PATH=/usr/local/mysql/bin:/Users/hanxu/.rvm/bin/:$PATH
Above is the content of my .bash_profile
Then rvm works.
Then I type:
rvm gemset use rails
It seems running well and shows:
Using ruby-1.9.3-p194 with gemset rails
However, when I examine it by asking rvm gemset name, it turns to be:
/Users/hanxu/.rvm/gems/ruby-1.9.3-p194
which is my default gemset, rather than "rails".
No matter how I set gemset, it always change to the default setting.
Can anyone tell me what's the problam?
Are you using an .rvmrc file?
https://rvm.io/workflow/rvmrc/
Your RVM installation is most likely incomplete. Look for this string in your .profile / .bashrc / .zshrc or whatever else you might be using
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
This command checks for existence of $HOME/.rvm/scripts/rvm and, if found, loads it into the shell. This effectively loads the RVM. So, if you don't find this command, add it and open a new terminal window, RVM should be there.
rvm has a command to fix sourcing:
rvm get stable --auto
the auto switch will update your *rc files, then it should be enough to open new terminal and it should be all fine.
Use this command to switch gemset.
rvm use <ruby version>#<gemset name> --create
This command will switch rvm to given gemset and create it, if it does not exist.
In my case, I needed to add the user to the rvm group before I could use rvm.
I have several old (pre-bundler / pre-rvm) Rails projects that use my system's gems.
Now I've installed RVM to ride the latest Rails version, but my old applications are now using a gemset: (I'm not sure exactly what I did to make this happen)
~/rails_apps/rapgenius >: echo $GEM_HOME
/Users/tom/.rvm/gems/ruby-1.8.7-p302
I want to use my system's gems by default, and, if I have an .rvmrc file in a directory, I want to use the gemset it specifies in that directory. Like this:
~/rails_apps/reader2000 >: cat .rvmrc
rvm 1.9.2#reader2000
~/rails_apps/reader2000 >: echo $GEM_HOME
/Users/tom/.rvm/gems/ruby-1.9.2-p0
How can I achieve this?
You can try
rvm use system --default
I have installed rails 3.0.10 and 2.3.5 in my machine. I wanna shuffle between them but I am unable to use 2.3.5. When I run a command, the system recognizes only 3.0.10.
rvm lets you easily manage multiple installs of Ruby, each with their own list of gemsets.
Edit: Based on your comment about looking into gemsets, I'll point out one of the single coolest features with rvm. Once you get your gemset setup, create a .rvmrc file in your Rails root directory. Add the following to it:
rvm 1.9.2#foo
Where "1.9.2" is whatever Ruby you're using and "foo" is the gemset name. rvm will automatically start using this set when you cd in to that directory.
Definitely use rvm, create a .rvmrc file in the root directory of each of your projects.
For rails 3 stuff, it should contain a single line: rvm 1.9.2#projectName
Replacing projectName with an identifier for your project. Then use rvm gemset create projectName
Everytime you go into that directory, you'll be using that version of ruby with that particular gemset so you won't mix up versions or ruby or gems!