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.
Related
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.
I'm a newbie in rails. I installed Rails(4) and Ruby using RVM.
I get an error whenever I run rails s or rails server on a different terminal.
It says
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
It only works on the first terminal I used to install rails on.
The left terminal is the one where i installed rails on
It looks like you havent added the rvm path in bashrc or bash_profile
/home/username/.bashrc
/home/username/.bash_profile
Add
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
and
source .bashrc
Your terminal likely isn't set to be a login terminal, so RVM isn't being setup correctly on new terminal instances.
See https://rvm.io/integration/gnome-terminal for how to configure your terminal as a login terminal.
Are you using gemsets? You can think of each gemset as an independent, compartmentalized "environment" that houses your rails installations.
If you've already installed rails under a gemset, are you making sure your new terminal window's environment is using the gemset that you installed rails on? When you open a new terminal window, it won't know which gemset to use, unless you configure it to use some default gemset. You can use the gemset you created by doing:
$ rvm use <YOUR_GEMSETNAME>
If you don't know/remember what gemsets you created, you can list them with the following command. Try using this command on the terminal that worked. It'll indicate which gemset you're using (then you can use that gemset name with the use command above):
$ rvm gemset list_all
This Rails tutorial does a good job of giving step by step instructions on installing ruby and rails with rvm properly. Just remember that with every new terminal that you open, you have to make sure you're using that gemset.
I recently created a new Rails project, and I believe I created a gemset for it before generating the app.
But when I encounter an error I get a message like this:
File /.rvm/gems/ruby-1.9.3-p194#project_1/gems/activerecord-3.2.8/lib/active_record/relation/finder_methods.rb
Even though I am in project_2. So in theory that should be ruby-1.9.3-p194#project_2 and not project_1.
What can be causing this and how can I fix it?
Thanks.
P.S. I am using RVM.
Edit 1:
I ran rvm gemset list and this is the output:
project_2$ rvm gemset list
gemsets for ruby-1.9.3-p194 (found in /Users/marcamillion/.rvm/gems/ruby-1.9.3-p194)
project_1
=> project_2
project_3
Edit 2:
I just ran gem install rails in my project_2 directory after I created the .rvmrc file for that project after verifying that it is indeed using the gemset for that project specifically. However, when I generate the error again, I am still seeing a reference to the gemset in project_1.
Edit 3:
The output for rvm current:
$ rvm current
ruby-1.9.3-p194#project_2
Edit 4:
Although, when I run rvm current in the same terminal window as my rails s I see:
$ rvm current
ruby-1.9.3-p194#project_1
So how do I set the gemset across all terminal windows for right now, and in the future?
You need to tell RVM which gemset to use. Try this:
rvm gemset use project_2
If that works, then you may wish to create a .rvmrc file in project_2's root directory so that it automatically switches to that gemset when you enter the directory:
cd /path/to/project_2
rvm --rvmrc --create 1.9.3#project_2
That'll create a .rvmrc in /path/to/project_2. cd out of the directory and back in, and it'll prompt you asking if you trust the .rvmrc file. By default, it'll only ask you the first time.
Edit:
It is important to note that when creating a new .rvmrc, you need to cd out of the project directory in all open terminal sessions (including rails s and rails console). Otherwise the app will continue using the gemset from project_1.
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
Ubuntu 11.
I do the following:
$ rvm --default use 1.9.2
and I get:
Using /home/md/.rvm/gems/ruby-1.9.2-p180
so that is good.
but when I now open a new terminal window I still get:
$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
If you put the RVM source line in your bashrc (in order to ensure that non-interactive shells have access to RVM), you will need to source .bashrc from your .bash_profile with the following as the last lines in your .bash_profile
if [ -f "$HOME/.bashrc" ]; then
source $HOME/.bashrc
fi
This pre-supposes that you have
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
in your $HOME/.bashrc. This is a good way to ensure that both interactive/login and non-interactive shells are able to find and load RVM correctly. Multi-User installs accomplish the same thing via the /etc/profile.d/rvm.sh file.
After that, you should have no problems defining a default Ruby to use via
rvm 1.9.2 --default
or
rvm use 1.9.2#mygemset --default
Its better to define a default gemset to use so as not to pollute your 'default' or 'global' gemsets.
If you are using non-interactive shells, be aware that they genereally operate in SH-compatibility mode which then requires you to set
BASH_ENV="$HOME/.bashrc"
in your $HOME/.profile in order you load RVM, or to set that within your script directly. The reason for this is that when bash is operating in SH mode it does not directly load .bash_profile or .bashrc as SH doesn't use those files, and bash is attempting to mimic the loading and execution process of the SH shell.
do an "rvm list" to see which Ruby versions you have installed.
then do this if you want to change the version only in one terminal session:
rvm use 1.8.7
if you want to select the default version for this user account, do this:
rvm use --default 1.9.2
See:
rvm use --help
See also this RailsCast:
http://railscasts.com/episodes/200-rails-3-beta-and-rvm
http://beginrescueend.com/
Late to party - anyway.
You did correctly set the default ruby version: rvm --default use 1.9.2
However, you need to update your Gemfile to the target ruby, because RVM references that file to select the working ruby version when you open terminal , that's why it reverted to the previous ruby version.
To Change the Default Version of ruby:
In Ubuntu
Go to default Terminal of Ubuntu and then follow the instructions:
1) Edit -> Profile Preferences
2) Select "Title and Command"
3) check "Run command as a login shell"
4) restart terminal
And after that run this command:
rvm --default use 2.2.4#gemset_name