We need a certain gem application run on a cron schedule, so we have a dedicated user set up to run this gem.
We are currently using ruby 1.9.2
[jobrunner#test-load] rvm list
rvm rubies
ruby-1.8.7-p299 [ x86_64 ]
ruby-1.9.2-p180 [ x86_64 ]
=* ruby-1.9.2-p290 [ x86_64 ]
ruby-1.9.3-p125 [ x86_64 ]
ruby-1.9.3-p374 [ x86_64 ]
ruby-1.9.3-p392 [ x86_64 ]
ruby-1.9.3-p448 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Unfortunately I need this user to run on ruby 1.9.3. Changing the default ruby version is not an option because rvm is installed system wide (/usr/local/rvm/bin/rvm) and other users on the system rely on 1.9.2.
If I were in an interactive session, it would be as simple as
rvm use 1.9.3
However, it appears I can't use rvm use in a non-interactive session (i.e. in the crontab). (I tried it by sticking that in my bashrc file and telling cron to look at my bashrc file. I ended up forkbombing myself..)
How do I get my crontab using a specific version of ruby via rvm?
From tty switch ruby version:
rvm use 1.9.3
You should set up cron with rvm:
rvm cron setup
then your crontab would look like this:
PATH="/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194#global/"
rvm_env_string='ruby-1.9.3-p194'
rvm_path='/usr/local/rvm'
rvm_ruby_string='ruby-1.9.3-p194'
RUBY_VERSION='ruby-1.9.3-p194'
GEM_HOME='/usr/local/rvm/gems/ruby-1.9.3-p194'
GEM_PATH='/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194#global'
MY_RUBY_HOME='/usr/local/rvm/rubies/ruby-1.9.3-p194'
IRBRC='/usr/local/rvm/rubies/ruby-1.9.3-p194/.irbrc'
Cron would use 1.9.3 ruby with the above
EDIT
Just noticed my text was not well formatted on SO, so I have reformatted it
You can source the rvm confined ruby from your script like this:
#!/usr/bin/env bash
# load rvm ruby
source /usr/local/rvm/environments/ruby-1.9.3-p448#projectX
# ..... rake, ruby, whatever you need your script to do
Related
Ok so first off I've seen almost all if not all the posts on this here and nothing has worked. Furthermore I don't know how but I have got this to work on a different environment which is basically a clone of my current set up. I just can't pin point what's different between the two.
Issue:
I have ruby-2.5.0 set as my default but on each new terminal session I get reverted back to ruby-2.3.3
So here's my RVM list
=> ruby-2.3.3 [ x86_64 ]
* ruby-2.5.0 [ x86_64 ]
2.5.0 set as my default, in my other env I simply ran
rvm use 2.5.0 --default
and I'd get 2.5.0 whenever I started a new session. That's not working here.
HERE is a gist with my bashrc, bash_profile, and zshrc files.
Got it working running these 2 commands
$ rvm alias create default 2.5.0
$ rvm default 2.5.0
This issue seems to relate to Default Ruby not loading with RVM, but the answer do not help me.
On my Ubuntu 14 LTS, I've got 2 rubies installed in rvm and set 2.2-head as default using rvm use 2.2-head --default. After reopening terminal (login shell is configured) 2.2 does not get set as current
$ rvm list
rvm rubies
=> ruby-2.1.5 [ x86_64 ]
* ruby-2.2-head [ x86_64 ]
# => - current
# =* - current && default
# * - default
I couldn't find any .ruby-version or .rvmrc in current ($HOME) folder (or its parents).
Meanwhile I tried removing system ruby (1.9.3), but this has no effect, too.
What did I miss?
Problem could be solved by rebooting system, although I don't know why this works
Have you followed the instructions on https://rvm.io/rubies/default?
When I input:
ruby -v
I get:
ruby 1.8.7
but with:
rvm list
I get:
=* ruby-2.2.1 [ x86_64 ]
# => - current
# =* - current && default
# * - default
What is causing this mismatch? How do I correct it so I always use 2.2.1?
I would guess there is something wrong with your $PATH and you are referencing the system ruby maybe? I would recommend double checking the install directions.
You could also try running again:
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
Finally, once you get that working, I also find using .ruby-version and .ruby-gemset files in repos/folders very helpful. See "Typical RVM Project Workflow" for more info.
Not sure if this issue is related to a recent Oh-My-ZSH update, but all of a sudden, my RVM default Ruby is not loading when opening a new Terminal window (instead, it loads the system Ruby).
I have added [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" to about every dotfile on my system (.zshrc, .zprofile, .zlogin, .profile, even .bashrc and .bash_profile for good measure).
RVM is loading when the session starts (I can manually switch to the default with rvm default), and $HOME/.rvm/bin is in my $PATH. If I switch to a directory with a .ruby-version and/or .ruby-gemset file, it loads that Ruby.
EDIT:
To clarify, my problem is that the default Ruby I declared with RVM (rvm use <RUBY VERSION> --default) is not being loaded when I start a new terminal session or when I cd out of a directory that has a .ruby-version file.
EDIT #2:
Here is the results of rvm list
{15:20}[]~ ➭ rvm list
rvm rubies
ruby-1.9.3-p550 [ x86_64 ]
ruby-2.0.0-p594 [ x86_64 ]
ruby-2.1.3 [ x86_64 ]
* ruby-2.1.4 [ x86_64 ]
So I half figured this out. I was attempting to set a default Ruby with the global gemset for that particular Ruby version (rvm use 2.1.4#global --default). When I set the default without the gemset, it persists and is loaded in each subsequent session.
In the past I have been able to load the default with a gemset. Not sure if this is an issue with the latest version of oh-my-zsh or rvm.
RVM doesn't use the default Ruby version on both my Mac and Ubuntu server.
This is what I get when I do rvm list on my Mac:
rvm rubies
* ruby-2.1.2 [ x86_64 ]
# => - current
# =* - current && default
# * - default
And what I get on Ubuntu:
rvm rubies
* ruby-2.1.2 [ i686 ]
# => - current
# =* - current && default
# * - default
They are already the default and only version available, but I have to manually type rvm use 2.1.2 each time when I need to do some Ruby stuff. I guess I could put that command into .profile or the like, but it feels hackish since I'm expecting RVM to use the default version.
Does anyone have a better solution?
I resolved the problem.
I tried rvm use ruby-2.1.2 --default multiple times and it didn't work. There's two things I did:
I moved this line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
in ~/.bash_profile to the last line. See "How to use "RVM --default" on MacOSX".
Somehow some application decided to add itself to this file and making it the first in the path.
Run rvm get head.
This solved the problem for me on my Mac.