I have been using these files all day... And then suddenly this is now what I get.
#!/Users/user969617/.rvm/gems/ruby-1.9.3-p0
puts "hello world"
require 'json'
output:
hello world
rub.rb:3:in `require': no such file to load -- json (LoadError)
from rub.rb:3
I can call it from the interactive ruby shell though... super strange.
Using /Users/user969617/.rvm/gems/ruby-1.9.3-p0
1.9.3p0 :001 > require 'json'
=> true
1.9.3p0 :002 >
Any ideas? I have restarted the computer ;)
------------------ update
I dont use any other require functions, but I just tried require 'Rake' which also returns True in irb, but go the same 'no such file to load'... so it's any require request it seems
You need to bootstrap RVM in your environment. Run this to add the bootstrapping code to your environment.
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
If that doesn't fix it, make sure that you have it installed with your current gemset (RVM supports sets of gems which get added and removed from the environment) gem list json If you don't have it, then gem install json
Related
on a CentOS 6.5 server, I installed ruby through rvm and set the ruby-2.0.0-p451 as default.
$ rvm --default ruby-2.0.0-p451
However, when I'm running script from Crontab
I got an error like
`require': no such file to load -- rubygems (LoadError)
so I checked ruby -v test.rb, it tells me that I'm using ruby 1.8.5 (2006-08-25) [x86_64-linux] not the default ruby-2.0.0-p451. And I also checked with /usr/bin/ruby.
$ /usr/bin/ruby -v
ruby 1.8.5 (2006-08-25) [x86_64-linux]
My question is how to use ruby-2.0.0-p451.
Thanks
It looks like, your path variable is not set correctly. It is generally defined in your ~/.profile, it should contain something like these 2 lines:
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads R
I just simply changed the /usr/bin/ruby as a link to solve the problem as below:
mv /usr/bin/ruby /usr/bin/_ruby
ln -s /usr/local/rvm/rubies/ruby-2.0.0-p451/bin/ruby
I'm trying to get ttscoff's TaskPaper to Markdown ruby script https://gist.github.com/511174 working. However, I use rvm, which seems to present some challenges.
-rjcode is a no-longer needed Unicode flag and -Ku is another encoding flag I can probably ignore.
I found instructions for adding rvm as a function to your script, but the script still errors as soon as it hits require ftools.
What I added is:
#!/usr/bin/env bash
# TaskPaper to Markdown converter
# Usage: tp2md.rb filename.taskpaper > output.md
# Load RVM into a shell session *as a function*
# 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"
fi
# Configure ruby and gemset
rvm ruby-1.9.2-p290#global
ruby <<-rb
puts "Hello!"
rb
Hello! outputs fine, but I get the following errors afterwards:
require: command not found
infile: command not found
prevlevel: command not found
begin: command not found
syntax error near unexpected token `('
` file = File.new(infile, "r")'
My problem seems to be related to the gem not getting pulled in. I've uninstalled ftools and reinstalled with rvm, but still no dice. Thankful for any help!
Your telling ruby to load the 'b' library.
-r library Causes Ruby to load the library using require. It is useful when using -n or -p.
This should work.
ruby -r ftools <<rb
puts "Hello!"
rb
Writing a script that cds into another dir, loads the correct rvm rvmrc file, then allows me to execute a rake task.
I have the below script working on my computer, but when others pull it down to their machine they get the following error "Ruby rvmrc is not installed".
Bundler.with_clean_env do
Dir.chdir("../some_dir") do
puts `source ~/.rvm/scripts/rvm && rvm --with-rubies rvmrc exec -- rake some_task`
end
end
I have the most up to date version of rvm (so do they) and I'm on mt.lion
I have tried creating a bash function like so...
function foo {
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" && rvm use #my_gemset
}
Or, replacing this line
rvm --with-rubies rvmrc exec
with things like...
rvm rvmrc load
rvm use <gemset>
rvm env --path -- ree-1.8.7#some_gemset
But none of it has worked. Thanks for the help
this should work:
~/.rvm/bin/rvm rvmrc trust ../some_dir
~/.rvm/bin/rvm in ../some_dir do rake some_task
I'm using ruby 1.8 and have gem https://github.com/delano/rye installed that need to remote ssh to amazon.
require 'rubygems'
require 'rye'
instance = Rye::Box.new('amazone_ip', :user => "ubuntu", :safe => false, :keys => "amazone_key")
I got errors by running those commands:
instance.execute 'rvm list' #bash: rvm: command not found
instance.execute 'ruby -v' #bash: ruby: command not found
It's ok if I run the command instance.execute ls -la.
I would think there is problem with $PATH load, that I have checked it
instance.execute 'echo $PATH'
#[/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games, , 0, ]
#But it's in server:
$echo $PATH
#/home/ubuntu/.rvm/gems/ruby-1.9.2-p290/bin:/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#global/bin:/home/ubuntu/.rvm/rubies/ruby-1.9.2-p290/bin:/home/ubuntu/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I'll wager you don't have rvm loading because its either not loading your local .bashrc or you don't have the RVM loading line (sourcing line) in your .bashrc, its in your .bash_profile. Just move the RVM line to your .bashrc and then source the .bashrc at the end of your .bash_profile.
If its calling bash in sh-compatible mode, then you can set BASH_ENV in your .profile and point it at your .bashrc which will then load RVM that way.
Try
instance.execute('source ~/.bash_profile && rvm list')
In case someone else finds it useful as this is an old question -
For a non-login shell the user's paths and environment variables are not loaded.
I needed to add this in my .bashrc file right at the very top.
[[ -s "/home/douser/.rvm/scripts/rvm" ]] && source "/home/douser/.rvm/scripts/rvm"
My RVM system-wide installation scripts are broken, both in the form of Linode StackScripts and Chef-solo Recipes.
Per the instructions on the RVM website, my scripts execute the following commands as root to install RVM on a system-wide basis:
echo "Installing RVM system-wide" >> $logfile
bash < <( curl -L http://bit.ly/rvm-install-system-wide )
cat >> /etc/profile <<'EOF'
# Load RVM if it is installed,
# first try to load user install
# then try to load root install, if user install is not there.
if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
. "$HOME/.rvm/scripts/rvm"
elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
. "/usr/local/rvm/scripts/rvm"
fi
EOF
source /etc/profile
The key piece above is the url http://bit.ly/rvm-install-system-wide. As of today, 3/24/2011, this url no longer in service. It results in a GitHub 404 error.
The following url on the RVM website used to contain the instructions for the system-wide install: http://rvm.beginrescueend.com/deployment/system-wide/. However, that url now redirects to the RVM homepage.
In the interests of getting RVM system-wide installation scripts to work again, what are the new instructions?
Here is my fix to install the last working version before he major change:
bash <( curl -L https://github.com/wayneeseguin/rvm/raw/1.3.0/contrib/install-system-wide ) --version '1.3.0'
This is working for me now in production. Good luck!
UPDATE
Also, if you are using the chef cookbook from https://github.com/fnichol/chef-rvm or something similar, you can use the following options:
:rvm => {
:system_installer_url => "https://github.com/wayneeseguin/rvm/raw/1.3.0/contrib/install-system-wide",
:version => "1.3.0"
}
Just received the following answer from the lead developer, wayneeseguin, on #rvm:
[12:53] "the author" merged it into the ain installer
[12:53] so you should be doing
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
# http://rvm.beginrescueend.com/rvm/install/
[12:53] the code has just changed and the documentation hasn't caught up
[12:53] for both root and user installs
It is true that RVM 1.5.1 will successfully install into /usr/local/bin just by installing as root. However, for some reason, all the existing Chef and Puppet provisioning scripts that are in use today do not appear to survive this version bump. This is unfortunate, as Wayne E. Seguin has made clear that RVM below version 1.5.0 will not be supported.
That said, we need our systems to work today. In order to continue to use RVM 1.3.0, which the existing scripts support, you need to replace the following line:
bash < <( curl -L http://bit.ly/rvm-install-system-wide )
With the following line (found by phlipper):
bash -c "bash <( curl -L https://github.com/wayneeseguin/rvm/raw/1.3.0/contrib/install-system-wide ) --version '1.3.0'"