RVM - Automatically use a certain Ruby version for a given command? - rvm

I have some commands that need particular version of Ruby e.g. Chef's knife command seems to work best with 2.0.0 while sup works best with 1.9.2. Is there a way, without writing a wrapper script or manually do "rvm use", that when I execute "sup" it will use 1.9.2 and when I execute knife it will use "2.0.0"?
I realise this question is not strictly "development" but there are lots of RVM questions on SO already so I figured it was a good place to ask.

rvm generates wrappers for you:
rvm wrapper 2.0.0 --no-prefix knife
rvm wrapper 1.9.2 --no-prefix sup
assuming you do not install this gems in all rubies the default from $rvm_path/bin/ will be used with loading proper ruby.

Related

YAML safe loading is not available

When I want to install compass with gem install compass, I occurred with this error:
YAML safe loading is not available.
Please upgrade psych to a version that supports safe loading (>= 2.0).
what The cause of this error and how can I solve the problem?
It sounds like the psych gem needs to be updated. Try running gem install psych and then gem update psych.
Suggested by looking at the psych readme file here: https://github.com/ruby/psych/blob/master/README.md
EDIT: you might also have to update your version of ruby. This depends on how you have installed ruby, but #ewerx has one suggestion in their answer.
To resolve this I first upgraded Ruby from 2.0.x to 2.4.2 (https://gorails.com/setup/osx/10.12-sierra):
rbenv install 2.4.2;
rbenv global 2.4.2
Then updated gems:
sudo gem update --system;
gem update
It may be sufficient to just update gems.
The following part of the post on https://gorails.com/setup/osx/10.12-sierra solved my issue.
We will be setting up a Ruby on Rails development environment on macOS 10.12 Sierra.
Older versions of OS X are mostly compatible so follow along as far as you can and then Google search for any problems you run into. There are plenty of people who have documented solutions for them.
Installing Homebrew
First, we need to install Homebrew. Homebrew allows us to install and compile software packages easily from source.
Homebrew comes with a very simple install script. When it asks you to install XCode CommandLine Tools, say yes.
Open Terminal and run the following command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Installing Ruby
Choose the version of Ruby you want to install:
Now that we have Homebrew installed, we can use it to install Ruby.
We're going to use rbenv to install and manage our Ruby versions.
To do this, run the following commands in your Terminal:
brew install rbenv ruby-build
Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
Install Ruby
rbenv install 2.5.1
rbenv global 2.5.1
ruby -v

How to use RVM in CSH environment?

I have installed RVM using following procedure (https://rvm.io/rvm/install)
curl -sSL https://get.rvm.io | bash -s stable --ruby --rails - it has installed RVM (single-user) in $HOME. (Question: How do I specify a non-default RVM installation path in above command?)
Updated $PATH in my ~/.cshrc to have RVM bin path as below. set path = ($HOME/.rvm/bin ${path})
prompt>which rvm
$HOME/.rvm/bin/rvm
prompt>rvm -v
rvm 1.26.9 (latest) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
prompt>rvm list
rvm rubies
# No rvm rubies installed yet. Try 'rvm help install'.
Though I have used --ruby and --rails in step (1), I noticed that Ruby & Rails were not installed as part of (1). So trying to install Ruby myself, using rvm install ruby
Per RVM installation instruction, I need to source $HOME/.rvm/scripts/rvm, which uses bash to execute. But our entire environment has tcsh as shell, and I cannot afford to change it.
prompt>source ~/.rvm/scripts/rvm
if: Too few arguments.
It is erroring out since our default shell is TCSH and the script is written in BASH.
prompt> echo $SHELL
/bin/tcsh
And we use ~/.cshrc to configure our environment.
Can someone help me to fix the setup, so that I can use RVM?
Thanks in advance.
I tried following options:
Using this as workaround now: How do I use RVM with tcsh? (it doesn't work good when I try running rvm use to switch Ruby Version.
prompt>rvm use 1.8.6-p383
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 an example.
http://po-ru.com/diary/using-rvm-with-tcsh/ does not help
RVM is not a function, selecting rubies with 'rvm use ...' will not work is not a solution for my problem. I verified it is not working.
Unfortunately, we are not using ~/.bashrc or ~/.zshrc environments? Does it mean RVM is not supporting CSH/TCSH environments?
Thanks for all your help in advance.

How to install rails bundle in the right place

I installed ruby-1.9.3 by my homebrew, so it locate on /usr/local/Cellar/ruby/1.9.3-p286/.
After installed Rails by rvm, I do command bundle install but the bundles were all installed to the /Library/Ruby/Gems/1.8/gems which is an old-version ruby installed with my OS X.
What can I do to let the bundles install in the right place?
Try this
$ rvm use 1.9.3--system
Use either rvm or rbenv to manage different versions of ruby. You could also consider JewelryBox, which does pretty much the same thing, but with a prettier GUI.

How do I install same version of ruby as different names with rvm?

After I installed a version of ruby with rvm, I noticed that some minor configuration issue on installation process. So I wanted to try to install with another configuration options, but I don't want to spoil the installed ruby at all.
So I just to attempt to backup the installed ruby before rvm reinstall.
(cd .rvm/rubies && mv ruby-1.9.3-p194 ruby-1.9.3-p194.org)
In my case, reinstallation fixed the issue, I didn't rollback ruby. So, I don't know this can work.
Are there any clean or correct way? Just for future references.
you can install named rubies:
rvm install 1.9.3-test1 [options]
and after it worked set it as default:
rvm use 1.9.3-test1 --default
or reinstall the original 1.9.3, named rubies are useful especially for testing compilation flags or patched rubies:
rvm install 1.9.3-performance --patch falcon
You can also have different gemsets with the same version using
rvm create gemset projectname

Rails 3: Ruby 1.9.2: does it need /usr/bin/ruby1.8?

I am trying to get the Rails tutorial by Michael Hartl going. I spent a lot of time fighting various libraries. So I removed all ruby software from my Ubuntu 10.4 system.
Then I installed Ruby 1.9.2.
$ ruby -v
ruby 1.9.2dev (2010-07-02) [i486-linux]
So far so good. Then I did
sudo gem install rails
After a long time, it finished the installation.
Then I ran
$ rails -v
bash: /usr/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file or directory
So...I have no /usr/bin/ruby1.8 on my system. How do I get Rails 3.0.3 to use my ruby at /usr/bin/ruby?
I appreciate any help you can give me.
Just to see if I could keep going, I tried
$ cd /usr/bin
$ sudo ln -s ruby1.9.2 ruby1.8
This let me keep going, but is it the right thing to do?
It took trying 3 different methods of installing and uninstalling Ruby, but I finally got it!
I found a great tutorial by Toran Billups which gives some great instructions. After analyzing what he did, it comes down to a few key concepts:
Some libraries that are independent of the Ruby version must be installed in the system (using "sudo apt-get").
Use RVM to install Ruby in your own account. i.e. no "sudo".
Use gem to install gems in your particular ruby environment. (i.e. no "sudo"). When you set 1.8 as the Ruby environment, the gems are installed in the RVM 1.8 tree in your environment. When you set 1.9.2 as the environment, gems are installed in the 1.9.2 tree in your environment.
Here, then, is the process.
Remove all Ruby programs (1.8.x and 1.9.2) and Ruby libraries from your Ubuntu 10.4 system.
Install RVM on your system, following the instructions at the RVM site(broken) RVM site.
Follow Toran Billups' tutorial, starting at the point where you install Ruby 1.8.7.
Follow the instructions at Michael Hartl's tutorial(broken) Michael Hartl's tutorial to get Rails 3.0 working with Ruby 1.9.2, github, heroku.com, rspec, spork, and autotest.
I had the same error after installing with RVM and opening new shells. The solution was to run:
$ rvm use 1.9.2 --default
P.S.
I'm running Ubuntu 10.04 and after two days of trial and error finally got rails 3 working with ruby 1.9.2. I highly recommend using RVM to install ruby a godsend!
By the sounds of it Bash is finding ruby1.8 when its running the #!/usr/bin/env ruby line from the rails script, even though it doesn't exist. Try /usr/bin/env which ruby to see exactly what interpreter it's trying to load.
I was also having a headache with this, and don't want to use RVM right now.
I saw that the shebang line for /usr/bin/gem was #!/usr/bin/ruby1.8 and that this was presumably the issue.
I made sure /etc/alternatives pointed to the correct gem script; this can be set with:
update-alternatives --config gem
Then I removed /usr/bin/gem and symlinked from /usr/bin/gem to /etc/alternatives/gem
It turns out the only difference in the gem scripts was the shebang line, so manually changing that would have worked too.
Solved by changing back the version of my current Ruby (using RVM) to 2.0.x.
When i installed rails (two days ago) it was under the 2.0.0 version. Yesterday i changed to 2.1.x. Today i tried the rails command and got the error.
So turning back to the RVM Ruby version i installed rails did the trick.
Sorry by the bad english.
P.S. Using Ubuntu 13.10