Setting the RVM path? - ruby-on-rails

I installed RVM, Ruby 1.9.2 and Rails 3.0.9 on Lion which works fine. Only problem is, after I close the terminal I need to execute this:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
for it to pick up RVM.I then need to make RVM use Ruby 1.9.2 first before I can do Rails stuff again.
How can I make this permanent?

After you first execute
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
you shouldn't need to do it again. That line appends the necessary file inclusion information RVM into your .bash_profile. If you are using bash (as opposed to zsh, ksh, csh, tcsh or any other shell), then RVM will be accessible each time you open a new session. If you are using a different shell, that line may need to be in a different startup file. For example, if you are using zsh, then you'll probably want to append it to your ~/.zshrc file.
Having done this, simply running rvm --default use ruby-1.9.2 once should ensure that you have the desired version of Ruby by default. Note, you should not need to add this line to your .bash_profile or similar.

try this
rvm --default use ruby-1.9.2

In order to make Terminal (e.g. bash) enable RVM every time you open it, edit ~/.profile and add the following line to it:
[[ -s "/Users/foo/.rvm/scripts/rvm" ]] && source "/Users/foo/.rvm/scripts/rvm" # This loads RVM into a shell session.
Then to make the RVM's version of ruby default, as fl00r has mentioned, run:
rvm --default use ruby-1.9.2
Alternatively, you can add an .rvmrc file to the root folder of your app that uses Rails 3.0.9 and specify which version of Ruby you want to use with that project there:
rvm ruby-1.9.2
Even better, you should create a gemset by running rvm gemset create rails-3.0.9 and update you .rvmrc file to become like this:
rvm ruby-1.9.2#rails-3.0.9
Then run cd into the project once again (you must cd into it once again), and run bundle install.
This way your project will have its own isolated gemset.

this also work for me
rvm --default use 1.9.2

Related

Remove RVM, Ruby and gems completely?

I had to downgrade Rails and now the gems, the versions, and everything, are completely messed up and I feel like jumping from my window.
I just want to destroy everything related with RVM, Ruby and gems to make sure I make a 100% clean reinstallation.
How can I do that?
Linux and installed as regular user ? Than all you need to do is:
rm -Rf ./.rvm
rm -Rf ./.gem
rm -f ./.gemrc
You can also check ~/.bashrc and ~/.bash_profile files for lines like this:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
This should be enough. If you've installed it in some custom way then try this:
$ rvm list # to see what version you have installed
$ rvm gemdir # to see where are gemfiles located
There is something like rvm remove as well but, if you want to just remove all, than it's not very interesting I think.
If you have installed everything via rvm a simple
rvm implode
will remove all traces of rvm including rubies and gems. Even (as far as I remember, I'm not testing it right now) the shell files are updated.
rvm implode which removes all ruby installations rvm manages, everything in ~/.rvm

RVM can not change gemset

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.

RVM switching to #global gemset instead of a specific one

When I enter my rails dir on server RVM switch to
/home/capistrano/.rvm/gems/ruby-1.9.2-p290#global/bin/bundle
although it should use ruby-1.9.2-p290#mygemset/bin/bundle as it works on my local machine. When I type rvm use 1.9.2#mygemset it works. Nginx server is also looking for gems in the #global gemset
my .rvmrc file:
environment_id="ruby-1.9.2-p290#mygemset"
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
then
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
fi
else
# If the environment file has not yet been created, use the RVM CLI to select.
if ! rvm --create use "$environment_id"
then
echo "Failed to create RVM environment '${environment_id}'."
return 1
fi
fi
I'm not sure if I understood you but you could place an .rvmc file in your rails folder and put something like this in it.
rvm use ruby-1.9.2#mygemset
Whenever you cd into that directory rvm will use settings from the .rvmc file.
RVM is going through rapid develpment so the syntax and functionality of commands sometimes vary. Anyway, I solved it with upgrading to stable RVM:
rvm get stable
which is now rvm 1.14.1 (stable). Afterwards commands like rvm 1.9.3-p194#mygemset --create
works perfectly.
Another thing I was missing is the new syntax for executing commands:
rvm #mygemset do bundle install
This will install all gems for given gemset and ruby specified in .rvmrc file

How to set default Ruby version with RVM?

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

Rails on Linux Mint 11

I have installed ruby via rvm on Mint 11 no problem. Installed gems, ditto. Installed rails via gem install rails, and when I type rails -v it returns the correct version. Until I close that terminal and reopen a terminal. When I do that and type rails -v I get the message
The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails
If I then type
rvm use 1.9.2-p180 --default
and then type rails -v I again get the correct version...until I close the terminal.
I should add that I have added a path statement to my .bashrc pointing to the 1.9.2-p180 directory in my .rvm directory.
Typing ruby -v always returns the correct version.
Create .bashrc file and add .rvm command
$ sudo touch ~/.bashrc
$ sudo gedit ~/.bashrc
(Add line to .bashrc file)
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
Logout and Login OR just update user profile from .bashrc with following command
$ . ~/.bashrc
Try adding this command to your .profile and reopening your shell:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Use project rvmrc files. You can see how to set this up here http://beginrescueend.com/rvm/best-practices/
That way you keep all your gems seperate for each project and it's dead simple to set up
Try which rails. Maybe there is a link to a stub that gives you the note.
If that is the case calling the full path might help, e.g. /usr/local/bin/rails

Resources