rake sometimes won't work until "rvm use" - ruby

I've got Ruby, Rails, Rake and friends all working pretty well using RVM on OSX, but when I start a new shell (new tab in Terminal.app) rake tasks seem to "lose" their environment:
$ rake my_module:my_task
Could not find uglifier-1.2.7 in any of the sources
Run `bundle install` to install missing gems.
If I issue "rvm use" (which, I believe merely prints the current ruby, but does not alter anything) then it works fine:
$ rvm use
Using /Users/username/.rvm/gems/ruby-1.9.3-p194
$ rake my_module:my_task # works fine now!
It seems to happen when a new shell is started. I have rvm installed as a single-user installation, with the following at the bottom of my .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
I've verified that my .bash_profile is in fact executing by putting some echo statements after that line; I see the echo on the command line when I open a new tab, so it seems to be working. Any idea why rake doesn't work without "rvm use"?

Try setting rvm ruby to default ruby
$ rvm use ruby-1.9.3-p194 --default
This should use the rvm ruby-1.9.3-p194 every time as default.

Related

Using RVM via bash script

I wanted to write a small bash script to automatically setup the correct ruby version and gemset for a new project. For testing I have rvm installed with ruby 2.3.1 and two gemsets: foo and bar.
Even a simple test like this doesn't return what expected:
$ rvm current
ruby-2.3.1#foo
$ ./script
Using ruby-2.3.1 with gemset bar
Using /(...)/.rvm/gems/ruby-2.3.1 with gemset bar
ruby-2.3.1#bar
$ rvm current
ruby-2.3.1#foo
Contents of the script:
#!/bin/bash --login
rvm gemset use bar
rvm use 2.3.1#bar
rvm current
Other operations like installing rubies or creating gemsets seem to work, I just can't get use to modify the current version used by the script caller. Any ideas?
The answer was obviously simple, I should have called the script using
. ./script

ERROR: Missing RVM environment file After Doing rvm upgrade command - Passenger 4.0.23

I was running ruby 2.0.0-p247 on my Mac Mini Server (Mavericks 10.9.1). I read that there was a security vulnerability so I decided to upgrade to use the latest Ruby patch 2.0.0-p353. I did the following commands:
gem update --system (RubyGems 2.1.11)
rvm get stable (RVM 1.25.0)
rvm upgrade 2.0.0-p247 2.0.0-p353 (which should have moved my gemsets)
There is nothing in my system that I can find that references 2.0.0-p247 in rvm which is what I expected. When I go to ~/myuser/.rvm/environments there is no file 2.0.0-p247.
I am now attempting to start passenger. I had version 4.0.23 enterprise installed. I attempted to run rvmsudo passenger-install-apache2-module but got an error.
cd /Users/myuser/.rvm/gems/ruby-2.0.0-p353#mygemset/gems/passenger-enterprise-server-4.0.23
/Users/myuser/.rvm/wrappers/ruby-2.0.0-p353# mygemset/rake apache2:clean apache2 RELEASE=yes
# /Users/myuser/.rvm/wrappers/ruby-2.0.0-p353# mygemset/rake apache2:clean apache2 RELEASE=yes
ERROR: Missing RVM environment file: '/Users/myuser/.rvm/environments/ruby-2.0.0-p247#LightBeCorp_Rails4Ruby2'
Here are statements in my .bashrc file related to rvm if this will help.
[[ -s "$HOME/.rvm/scripts/rvm" ]]
PATH="$PATH:$HOME/.rvm/gems/ruby-1.9.3-p327#mygemset/bin:/.rvm/rubies/ruby-1.9.3-p327/bin/ruby:/.rvm/rubies/ruby-1.9.3-p448/bin/ruby:/.rvm/rubies/ruby-2.0.0-p353/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
I did a rvm list rubies command. ruby-2.0.0-p247 is not listed.
Any help would be appreciated. I will continue looking. I plan to post a link to this in the Phusion Passenger group.
UPDATE 12/21/2013 12:20 pm
I updated my .bashrc file to the following since I no longer use the other rubies in my Rails applications. I still get the error when I try to run rvmsudo passenger-install-apache2-module.
[[ -s "$HOME/.rvm/scripts/rvm" ]]
PATH="$PATH:$HOME/.rvm/rubies/ruby-2.0.0-p353/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
looks like a bug, please open a ticket here: https://github.com/wayneeseguin/rvm/issues
Indeed this was a bug, to fix it run:
rvm get head
rvm gemset reset_env
you can repeat the reset_env operation for every gemset that is broken:
rvm ruby#gemset do rvm gemset reset_env
There might be a cached bin file in your RVM path. In my case, it's "/usr/local/rvm/bin/unicorn"
Also, you may not directly having the gem in your Gemfile. In my case, I do not have "unicorn" in my Gemfile although I had "capistrano-unicorn".
So that the system will try to use the global cached file "/usr/local/rvm/bin/unicorn".
The file's content may using a ruby that you no longer use.
if [[ -s "/usr/local/rvm/environments/ruby-2.0.0-p247" ]]
then
source "/usr/local/rvm/environments/ruby-2.0.0-p247"
exec unicorn "$#"
else
echo "ERROR: Missing RVM environment file: '/usr/local/rvm/environments/ruby-2.0.0-p247'" >&2
exit 1
fi

RVM warning when installing Passenger on the Mac

Installing Passenger on the Mac runs into this problem.
Any suggestions?
sudo passenger-install-apache2-module
...
* Checking for Zlib development headers...
Found: yes
Location: /usr/local/include/zlib.h
Your RVM wrapper scripts are too old, or some wrapper scripts are missing. Please update/regenerate them first by running:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
If that doesn't seem to work, please run:
rvmsudo rvm wrapper [] --no-prefix --all
First I did:
$ rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. export rvmsudo_secure_path=1 to avoid the warning.
which re-installed rvm and then I did:
$ rvmsudo rvm wrapper [] --no-prefix --all
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no `secure_path` in `/etc/sudoers`. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.
awk: nonterminated character class ^[]=
source line number 1
context is
>>> /^[]=/ <<<
sed: 1: "s#^[]=##
": unbalanced brackets ([])
Unknown ruby interpreter string component: '[]'.
Could not load ruby [].
Add to your ~/.profile or ~/.bash_profile
export rvmsudo_secure_path=0
You may try to install passenger without sudo.
$ passenger-install-apache2-module

Why is Ruby bundler (w/ whiskey_disk and RVM) complaining that an installed Gem is not >=0?

This is my error message:
Running rake deploy:post_setup...
rake aborted!
You have requested:
nokogiri >= 0
The bundle currently has nokogiri locked at 1.5.5.
Try running `bundle update nokogiri`
Is this message telling me that 1.5.5 somehow does not meet the ">= 0" requirement? That doesn't sound right.
If I am interpreting this wrong, how should I interpret it?
(Ruby is jruby-1.6.7.2, bundle is 1.1.4. This rake task is actually run via whiskey_disk, if that's important.)
== EIGHT MONTHS LATER ==
I'm finding the same error. Again, trying to use whiskey_disk, so I suspect this is whiskey_disk-related.
This time, it's with the bcrypt gem.
3052 ~/dev/myproj$ bundle exec wd setup --to=grant
Deploying grant#<myserver>.com...
grant#<myserver>.com's password:
Repository already cloned to [/home/grant/myproj]. Skipping.
Running rake deploy:post_setup...
rake aborted!
You have requested:
bcrypt-ruby >= 0
The bundle currently has bcrypt-ruby locked at 3.0.1.
Try running `bundle update bcrypt-ruby`
Again, what the heck? I'm requesting something greater than 0, and it's complaining because the bundle has the gem and it's greater than 0! What's the problem?
The Gemfile contains simply gem 'bcrypt-ruby' - no version specified. Version 3.0.1 should be perfectly acceptable.
I've tried doing bundle update and bundle update bcrypt-ruby on the target server, but neither changes anything.
You are probably not using the correct ruby. Check which ruby is being used after you ssh into the machine. If you're using rvm, I would just uninstall the system ruby.
The problems came down to the fact that my RVM's Ruby wasn't being used by any of the remote commands. They kept using the distro's non-RVM Ruby.
So, two fixes were needed:
Needed to change the RVM path line in my .bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
need to be changed to prioritize RVM, like this:
PATH=$HOME/.rvm/bin:$PATH # Add RVM to PATH for scripting
I needed to load RVM in my post_setup.sh and post_deploy.sh scripts, so that the succeeding rake commands would use my RVM ruby.
This was accomplished by adding the following to each:
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit -1
fi
(The latter was clearly not written by me, given how polished it is. I lifted it from one of my firm's other projects, where they've clearly dealt with this before.)
I also need to run bundle install in my post_setup.sh and post_deploy.sh scripts. This must occur before whiskey_disk starts running Rake, so including it in the Rake script itself is not sufficient.
And now I have whiskey_disk deployments working smoothly.

RVM problem with default ruby version

when i execute following command
$ rvm --default use 1.9.2
$ ruby -v
i got following result:
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
i can't understand why is not
ruby 1.9.2p0...
If u installed correctly, most likely its is path problem.
Solution 1: Manually add the ruby1.9.2.p0 path into ur $PATH
Solution 2: Try run:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Type rvm info.
All paths should reflect rvm's installation in your home directory.
If not, odds are good you didn't follow the "Post Install" directions for rvm, and need to go through them, and the troubleshooting section that follows it.
Maybe you should to try
rvm reload
or try to type
rvm info
hope that will help you
Maybe you should invoke
rvm reload
or try to open up a new shell and then again
ruby -v
hope that works for you...
You can try running which ruby to see where your ruby is running from. If you've set up your rvm correctly and followed all the steps, it should look something like /home/username/.rvm/rubies/ruby-1.9.2-p136/bin/ruby. Also, make sure you added the line to your .bashrc file as specified in rvm-install notes.
I've found this rvm setup tutorial to work flawlessly on several different machines: http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you, including Ubuntu, Fedora, and even on a Mac (with a few adjustments).

Resources