How to permanently switch ruby -v 1.8.7 to 1.9.3 - ruby

By using these commands
source ~/.rvm/scripts/rvm
rvm use 1.9.3 --default
The version in current session is 1.9.3 but when I close terminal and reopen ruby version comes back to 1.8.7.
Do I need to add something to the .bash_profile ?
Edit: I found the another way is when I reopen terminal everytime just type source .bash_profile. The version then is 1.9.3. Is there anyway to execute the .bash_profile permanently ?

Yes you need to add something to your bash profile. See here:
https://rvm.io/rvm/basics/
Quote:
The rvm installation documentation instructs you to put the following line at the very end of your bash profile:
# This loads RVM into a shell session
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

Create a file named .rvmrc with the text rvm use 1.9.3 --default.

We're treading into sysadmin waters here but one possible explanation might be because of how you're logging into your shell and your OS. See the discussion of what files are loaded by your shell here and what makes up a login vs. non-login shell here.

Related

RVM is not a function, selecting rubies with 'rvm use ...' will not work

List the ruby versions
console:~$ rvm list
rvm rubies
ruby-2.0.0-p481 [ i686 ]
# => - current
# =* - current && default
# * - default
Try to use a specific version of ruby
console:~$ rvm use 2.0.0
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
Your console is not running as a login shell and hence have no access to rvm function. If you are running Ubuntu, you can:
Open console
Select Edit -> Profile Preferences
Select tab: Title and Command
Check box 'Run command as a login shell'
Restart terminal
Type bash --login from your terminal. And then give rvm use 2.0.0
It seems like your rvm does not load ".bash_profile" properly. I have done to fix it in MAC OS X or Ubuntu 14.04 by opening terminal and write:
source ~/.rvm/scripts/rvm
My env is OSX Yosemite. Had the same issue .... solved by adding the following
1) edit and add the following line to .bash_profile file.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
2) Restart terminal and try RVM command again
If you don't want that every time you open a terminal, do the suggestion above again, just add
source ~/.rvm/scripts/rvm
at the end of ~/.bashrc
The error is due to rvm is not running as in login shell. Hence try the below command:
/bin/bash --login
You will able run rvm commands instantly as login shell in terminal.
Same principle as other answers, just thought it was quicker than re-opening terminals :)
bash -l -c "rvm use 2.0.0"
You need to add source ~/.rvm/scripts/rvm to ~/.your_shellrc file. From now when you load a shell, rvm will be loaded.
For example:
if you are using zsh shell, need to add in ~/.zshrc file
if you are using bash shell, need to add in ~/.bashrc file
And then open a new tab to see the effect.
For me in Ubuntu(18.08), I have added below line in .bashrc and it works.
source /home/username/.rvm/scripts/rvm
Please add this line.
I think this more generic solution
echo 'source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
Following work for me in ubuntu 19.1
source ~/.rvm/scripts/rvm
From a new Ubuntu 16.04 Installation
1) Terminal => Edit => Profile Preferences
2) Command Tab => Check Run command as a login shell
3) Close, and reopen terminal
rvm --default use 2.2.4
If RVM was installed with dedicated ubuntu RVM installer https://github.com/rvm/ubuntu_rvm the path to RVM scripts will be different /usr/share/rvm/scripts/rvm. So to add it to your .bashrc run the following command:
echo 'source "/usr/share/rvm/scripts/rvm"' >> ~/.bashrc
FWIW- I just ran across this as well, it was in the context of a cancelled selenium run. Perhaps there was a sub-shell being instantiated and left in place. Closing that terminal window and opening a new one was all I needed to do. (macOS Sierra)
Usually this is caused by shell initialization files. Search for PATH=... entries.
You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
To fix it temporarily in this shell session run: rvm use ruby-2.6.5
To ignore this error add "rvm_silence_path_mismatch_check_flag=1" to your "~/.rvmrc" file.

RVM Ruby installation not successful

I'm trying to install ruby using rvm on linux debian. This is my problem:
Ruby didn't work at all in the terminal (that is, it said: ruby:command not found.
Then I followed this thread RVM ruby installation issue and it worked. However, after I closed that terminal and opened a new one, it didn't work anymore.
Do I have to change something in the autostarts? Can someone please help me!!
Check if your ~/.profile file contains:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
and your .bash_profile file contains:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if it have it and still don't work add this line to your ~/.bash_profile
source ~/.profile
I'm assuming you are using bash as your shell. You may want to check it in your user preferences (depend on your distro).
I assume the installation worked, what did not worked is you missed to use the installed ruby:
rvm use ruby-2.1.0
in your case it would print you a warning about not using login-shell - follow the instructions, they ae there to help you

Ruby versions differ in Terminal & bash

In Terminal, ruby -v gives me:
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
But if I type /bin/bash then ruby -v I get:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
I suspect this is something to do with my PATH config(s). My $PATH variable is different in both the above environments. There are other issues e.g. rvm won't run unless I go into bash mode.
For info, my ~/.bashrc contains:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Looks like "login shell" is not enabled, you need to enable it in Terminal Emulator Preferences, sometimes it is needed to use /bin/bash --login.
There are also known issues with ZSH, but it seams to be unrelated.
Try which ruby from "terminal" and "/bin/bash". Your 1.9.3 is inside your ~/.rvm path.
Type rvm info. You should get a list of the settings for RVM.
In your ~/.bashrc OR ~/.bash_profile, you should have RVM's initialization code. If you don't you didn't install RVM completely and need to finish. Read all the instructions on the RVM installation page.
This was not due to a $PATH problem. What I've learned is that RVM cannot be run unless you change your default login shell to either Bash or ZSH. Just firing up Terminal in Mac won't work. You make the global change to using Bash like this:
chsh -s /bin/bash
(swap /bin/bash for whatever your bash path is, find out using which bash).
The RVM website does say that bash>=3.2.25 is a prerequisite, but doesn't say what that is or how to check whether you have it. It also advises you to run rvm requirements to check what you need - and you can't run this unless you change your shell (all quite confusing for somebody new to this).
Thanks to the replies above for getting me there in the end.
See also: Bad: modifier error when installing RVM

OSX Lion New bash session rvm default ruby not used

I use OSX Lion. I have installed RVM and have put this line in my .bash_profile file.
[[ -s "/Users/Anand/.rvm/scripts/rvm" ]] && source "/Users/Anand/.rvm/scripts/rvm" # This loads RVM into a shell session.
I installed ruby-1.9.2-p290 and set it as default rvm ruby with this command:
rvm use --default ruby-1.9.2-p290
And when I checked ruby-v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
The problem is, every time I open a new terminal window or a tab, the default ruby is not getting set. The system ruby is instead getting used. ruby -v gives this:
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.3.2]
This also happens with reading .rvmrc file in a ruby project. When I'm inside a project and when a new tab gets opened, it gets me into the project directory but is not setting ruby according to .rvmrc in that project. What should I do to fix this?
I got the problem. It was with $PATH. I have to put rvm related line in the .bash_profile as the last line.
Old .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
source $HOME/Dropbox/dotfiles/bashrc
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
export PATH=/Library/PostgreSQL/9.0/bin:$PATH
New .bash_profile
source $HOME/Dropbox/dotfiles/bashrc
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
export PATH=/Library/PostgreSQL/9.0/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
And it worked. New windows and new tabs open up correctly with the default ruby i.e, ruby 1.9.2
I just fixed this very same issue. Turns out it was a path issue.
try this
➜ ~ which ruby
if you are getting /usr/bin/ruby, the path to your original ruby installation is overshadowing the default install in your RVM installation.
I added the path to RVM before the path (see below) to /usr/bin/ruby and it works as expected.
I use zsh as my shell, so I had to add this manually to my .zshrc
export PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting<br />
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
if you use bash
Your .bashrc probably looks like this
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
change it to this:
PATH=$HOME/.rvm/bin:$PATH # Add RVM to PATH for scripting
and make sure you .bash_profile has this:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
and you should be good to go.
Of course this means that your shell is going to look in your RVM directory first when looking for any command, but thats never caused any issues for me.
Question #1:
The command as listed is, you had switched '--default' and 'use'.
rvm --default use ruby-1.9.2-p290
Check if default is actually set:
$ rvm list default
Default Ruby (for new shells)
ruby-1.9.2-p290 [ x86_64 ]
Some other troubleshooting tips in case that doesn't work. Are you sure your bash profile file is being loaded? Try just having 'source "/Users/Anand/.rvm/scripts/rvm' instead of the check, maybe something is wrong with the path? Username does that begin with capital letter?
Question #2: You must cd into the directory with the .rvmrc file explicitly for the magic to happen. I suppose starting a console in a certain location doesn't trigger rvm. I run into this when using pushd and popd to switch between folders.
Try this first if rvm --default use doesn't work:
sudo rvm alias create default 1.9.2

TextMate, rvm and TM_RUBY

In the TextMate RVM instructions the text it says to set TM_RUBY to /Users/wayne/.rvm/bin/textmate_ruby and in the image it shows it set to rvm-auto-ruby. I decided to set it to rvm-auto-ruby thinking that it would use RVM's default Ruby version.
When running Command R in the RSpec.bundle having TM_RUBY set to rvm-auto-ruby will result in a load error. When you set it to textmate_ruby it works.
The only problem here is that TextMate doesn't always use the default version of Ruby since it's hardcoded in that file.
/Users/jspooner/.rvm/bin/textmate_ruby:
#!/usr/bin/env bash
if [[ -s "/Users/jspooner/.rvm/environments/ruby-1.9.2-head" ]] ; then
source "/Users/jspooner/.rvm/environments/ruby-1.9.2-head"
exec ruby "$#"
else
echo "ERROR: Missing RVM environment file: '/Users/jspooner/.rvm/environments/ruby-1.9.2-head'" >&2
exit 1
fi
So two questions:
What should TM_RUBY=rvm-auto-ruby actually do?
Is there a way to have TextMate use the RVM default?
Setting TM_RUBY to your-path/rvm-auto-ruby
http://rvm.io/integration/textmate/
should load whatever ruby and gemset is indicated in the .rvmrc file located in the project and if none default to rvm default. I just got this working and it is very smooth. I did need to get the latest version of rvm
rvm get head
to make it work and restart Textmate. Hope that helps.
See your other, similar, question Rspec bundle is broken in TextMate and rvm.
To help others chasing this same issue, the solution seems to be at: RVM / Textmate doesnt recognize .rvmrc Options.
Basically you replace the ~/.rvm/bin/textmate_ruby soft link with a file. This is what I did:
cd ~/.rvm/bin
mv textmate_ruby old.textmate_ruby
Create a shell script called textmate_ruby in the same directory to replace the soft-link, using the following contents:
!/usr/bin/env sh
source ~/.rvm/scripts/rvm
cd .
exec ruby "$#"
chmod +x textmate_ruby
Before doing this change I'd see my system Ruby's version (1.8.7) displayed if I did CMD+R to run the following script in TextMate:
puts RUBY_VERSION
Evaluating the script using CMD+CNTRL+SHIFT+E gave me 1.9.2.
After switching to use that script both point to Ruby 1.9.2, so at least there's some consistency now. I don't see TextMate tracking my currently set RVM Ruby version yet; Instead it's using the default version set in RVM: rvm use 1.9.2 --default. This is still a step forward because I can control which Ruby TextMate uses by adjusting my --default.
If you decide you want to revert later, just rename, or delete, the script and reverse step 2 above.

Resources