After Installation RVM and Ruby 1.9.3 every Bash path change RVM Initialization Script is printed - ruby

I installed the latest RVM - Ruby Version Manager - and installed Ruby 1.8.7 and 1.9.3 on OSX Lion with XCode 4.3.3 using clang rvm install 1.9.3 --reconfigure --debug -C --enable-pthread --with-gcc=clang as the regular way did not work due to a GCC error. I did get one error clang: error: unsupported option '--with-libyaml, but Ruby 1.9.3 worked and I could run WPScan that needs at least 1.9.2 .
But now every time I run a command to change folder such as cd I get a long Bash script printed related to RVM - see http://pastebin.com/UAm38Vcm and:
.
How can I stop it from doing that?
Update I
Added a comment at RVM at Github as well https://github.com/wayneeseguin/rvm/issues/1039 , but as that issue is not 100% related and as I need this solved as soon as possible I opened a thread here with more data.
Update II
I realized the RVM Initialization script is the one that is being printed: https://github.com/wayneeseguin/rvm/blob/master/scripts/initialize . No idea why though..
Update IV
My .bashrc
# define aliases
alias sudo='sudo '
#alias ruby='ruby1.9'
alias apacherestart='sudo apachectl -k restart'
# define hist properties
HISTFILESIZE=1000000000
HISTSIZE=1000000
# define path to programs
PATH=/opt/local/bin:opt/local/sbin:/opt/subversion/bin:/opt/local/apache2/bin/:/opt/local/lib/python2.4/site-packages/django/bin:$PATH
# define manpath
MANPATH=/opt/local/share/man:$MANPATH
# export env vars
export HISTFILESIZE HISTSIZE PATH MANPATH
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
My .bash_profile
source ~/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

Your cd command has somehow become aliased or a function has been created named "cd".
You can undo those with either:
unalias cd
or
unset -f cd

You should be able to revert temporarily with
unalias cd
It appears that you will need to figure out what was changed in your .bashrc and revert all those changes. If the installation script is at all sanely written, it should have made backups, or document somehow what was changed.

Related

Need to Fix PATH in my bashrc File for RVM

I did a clean install of my operating system recently and copied my old .bashrc file from a backup. I installed rvm version 1.26.10 (latest stable version). I installed ruby 2.2.0. When I source the .bashrc file I get the following error:
Warning! PATH is not properly set up, '/Users/myusername/.rvm/gems/ruby-2.2.0#mygemset/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.2.0#mygemset'.
Here are my PATH statements. The first line I included here is one that was in the new install of RVM in the .bash_profile file. I copied them into .bashrc. I'm also running postgres.app which requires the last statement in order to set it as the current PostgreSQL instance.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
export PATH="$PATH:$HOME/.rvm/bin"
export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH
I started with the .bashrc file recommended by the Ruby on Rails Tutorial by Michael Hartl (the version current in 2011 or 2012) and the settings used by RVM back then. I know things have changed a bit since then.
My bash knowledge is limited so any help would be appreciated.
UPDATE: 2/2/2015 2:40 pm CST
I changed my bash statements to the following and got rid of the warning:
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
UPDATE: 2/2/2015 5:14 pm CST
Here are my Bash statements:
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql"
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Here is the output for echo $PATH:
/Users/username/.rvm/gems/ruby-2.2.0#gemsetname/bin:/Users/username/.rvm/gems/ruby-2.2.0#global/bin:/Users/username/.rvm/rubies/ruby-2.2.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/Users/username/.rvm/bin:/Users/username:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql:/Users/username/.rvm/bin
My RVM wouldn't stop complaining about PATH even though the last thing in my .bashrc was this line:
# RVM
source ~/.rvm/scripts/rvm
So I just redirected the complaining to /dev/null:
# RVM
source ~/.rvm/scripts/rvm > /dev/null 2>&1
rvm use default > /dev/null 2>&1
The last line also makes sure RVM is first in PATH, so it doesn't really have anything to complain about.
rvm expects its $PATH stuff to come first in $PATH. You should add items to the $PATH before sourcing rvm, not after.
After dealing with this for several days I decided to go ahead and continue to proceed with my implementation of postgres.app with the warning message I got with RVM. I ran my original bash statements in a different order.
export PATH="$PATH:$HOME/.rvm/bin"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH
I was successful in implementing postgres.app. I still get the warning message but my Ruby on Rails applications are able to find the correct gems and run successfully.
You should add the line like this
export PATH= '/Users/myusername/.rvm/gems/ruby-2.2.0#mygemset/bin:other"
Maybe that can help you

RVM and Gemfile - not always loading correct ruby, only when 'cd .. & cd myproject'

TL;DR: Every time I open a new iterm2 tab, rvm goes back to default version, it doesn't use the Gemfile ruby version
My Gemfile has
source 'https://rubygems.org'
ruby '2.0.0'
and I use rvm 1.25.14.
RVM is smart and reads the ruby version in gemfile, except for this edge case
Doing
# NOTE: iterm2
$ cd myproject
$ ruby -v
> ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.5.0]
but cmd+t, creating a new tab, staying in that directoy,
$ pwd
>../myproject
$ ruby -v
> ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
ruby 1.9.3 is my default, which is fine. What am I missing in my bash (or .zshrc ) ? to make this work?
#FILE .zshrc
#...stuff
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Using cmd+d, splitting the terminal vertically, has the same problem. rvm goes to default, ignoring Gemfile. Thanks for helping guys !
This should be shell- and terminal-agnostic (unfortunately I can't test it on iterm2 since I don't have any Mac machine):
Add cd ${PWD} to your .zshrc and this should force RVM to load current gemset.
Just add cd . in .zlogin after the RVM script.
Use RVM's Built-In Ability to Reload Configuration Files in the Current Directory
RVM leverages the cd command, so while there may be a specific solution for your situation the more general solution is to use direnv, dotenv, or similar to ensure that you're triggering RVM properly when changing directories.
In my personal experience, one of the two placed into your project's .envrc or similar will resolve many issues, and highly recommend direnv with or without its standard library's ruby layout or use commands. For example:
read in the current directory's .ruby-* or .rvmrc files
rvm use .
Reload RVM, which will re-read various dotfiles if the relevant ~/.rvmrc variables have been exported (see dotfile settings in next section).
rvm reload
The first option is best IMHO, and seems to "just work" on all my Bourne-compatible shells, but the other should work too.
Some Key ~/.rvmrc Dotfile Settings
With either of the solutions above, you may need some of the following items set in your global ~/.rvmrc file:
export rvm_gemset_create_on_use_flag=1
export rvm_install_on_use_flag=1
export rvm_project_rvmrc_default=1
Which ones you really need will somewhat depend on how you expect RVM to behave under any given set of circumstances. However, I've found that using RVM's ability to reload its settings (rather than relying on the cd hooks, and calling that functionality directly to be much more reliable. Your mileage may vary.
See Also
https://rvm.io/workflow/rvmrc
https://rvm.io/workflow/projects
I seems that for a local open terminal rvm don't load its scripts. Add the code to the end of .bashrc, it then should:
if [ -z "$MY_RUBY_HOME" ]; then
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
fi

rvm on OS 10.9 a few problems: second export path to .bash_profile, missing 2.0 path, and missing files

1)
I have this error every time I load a new bash terminal
-bash: /etc/profile.d/sm.sh: No such file or directory
-bash: /etc/profile.d/rvm.sh: No such file or directory
I saw this previously asked question with the answer to simply delete the references from .bashrc. But the answer is unaccepted and unvoted and the references to these files are not in .bashrc but in ~/etc/profile
I should note that I don't have a profile.d directory under /etc. I have files profile and profile~orig
2)
RVM added a second export path after I ran rvm get stable, but did not include a reference to Ruby 2.0.0 in either.
.bash_profile
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=/usr/local/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/mcb/.rvm/rubies/ruby-1.9.3-p448/bin:/Users/mcb/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
My instinct is to combine them into one, eliminate repeats, and add the references to ruby 2 manually. I also added the $PATH: myself, since that didn't work the first time either.
3)
This is clearly not right
my-macbook-pro:~ mcb$ rvm get sable --auto-dotfiles
Warning! PATH is not properly set up, '/Users/mcb/.rvm/gems/ruby-2.0.0-p247/bin' is not available,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p247'.
cat: /Users/mcb/.rvm/help/get: No such file or directory
So, long story short I'm starting to get worried about trying to fix anything else myself without some sort of guidance for fear of just making things worse.
for 1) check /etc/profile for those two files references
for 2) remove export PATH=/usr/local/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/mcb/.rvm/rubies/ruby-1.9.3-p448/bin:... from ~/.bash_profile
for 3) rvm get sable => rvm get stable
I think the problem is that you are adding ruby 1.9.3 explicitly in your PATH, and that's a job that rvm shoud do.
In my case I have no direct reference to any of the ruby installations in my PATH.
Try cleaning your path from anything ruby and rvm related, and let rvm load as a function.
This is the .bash_profile on my computer (with rvm and brew working):
export PATH=/usr/local/bin:/usr/local/sbin:$PATH:/usr/local/opt/ruby/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
To check if rvm is correctly configured you can run:
type rvm | head -n 1
The result should be: "rvm is a function"
Checkout rvm official webpage for more details on how it works: https://rvm.io/rvm/install

RVM and Jenkins setup

I am new to Jenkins CI. I'm install RVM in my remote Jenkins and when I execute below shell.
#!/bin/bash -x
source ~/.bashrc
rvm use 1.9.3#rails-3.2.3
I get following errors.
+ source /var/lib/jenkins/.bashrc
++ PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/var/lib/jenkins/.rvm/bin:/var/lib/jenkins/.rvm/bin
+ rvm use 1.9.3#rails-3.2.3
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal settings to allow shell login.
Please visit https://rvm.io/workflow/screen/ for example.
What does it mean? I don't have any idea. Please help me.
UPDATED: I'm tried below script but I still get errors:
#!/bin/bash -x
source /home/zeck/.bashrc
[[ -s ".rvmrc" ]] && source .rvmrc
export RAILS_ENV=test
bundle install
Errors:
/tmp/hudson457106939700368111.sh: line 5: bundle: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Jenkins build shell can't detect RVM, gemsets and gems. What should I do?
UPDATED 2: Therefore jenkins can't detect ruby.
+ ruby -v
/tmp/hudson2505951775163045158.sh: line 5: ruby: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILUR
I'm not using any jenkins plugn and I'm just run script from Build->Execute shell section.
As the error message suggests, RVM expects an login shell. Changing the hashbang line to #!/bin/bash -xl should resolve this.
try:
. $(/home/RVM_USER/.rvm/bin/rvm env 1.9.3#rails-3.2.3 --path)
make sure you run the stable RVM:
rvm get stable
NOTE:
Last Jenkins version does not always accept "source", but ".".
RVM_USER is the user that installed RVM.
Alternatively you can also export the RVM command in the main PATH.
Yes, apparently you miss the $HOME/.rvm/bin in your PATH. I am using rvm successfully from Hudson on Mac OS X. First thing to notice is that, unless you define BASH_ENV environment variable (ENV for sh), .bashrc is called automatically only with interactive non-login shell. Such a shell is started when you do - for example - the following from the command line:
$ /bin/bash
When you use #!/bin/bash in your script, .bashrc will not be called.
To make rvm work with Hudson, I have the following in my .bash_profile:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Thanks to [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" I have rvm enabled every time I start new terminal window (interactive, login shell).
I do not put anything in my .bashrc, especially I am not sourcing rvm scripts there. Nothing wrong with that, but if any other scripts makes something stupid like setting `export BASH_ENV=$HOME/.bashrc' and then invoke non-interactive shell, you see what may happen - it is actually easy to forget.
Therefore, instead of loading things to your .bashrc, it is better to keep your script independent from any shell startup file and make sure that the correct environment is set up within the script. I still keep $HOME/.rvm/bin in my .bash_profile, but then I include the following at the beginning of my script:
#!/bin/bash
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
rvm use 1.9.3-head#MyGemSet
set -ex
cucumber # just an example
Notice the -e option which forces the script to exit with error code if any command following set -ex fails. This is behavior you may want when using the script with Hudson.
It is incorrect to say that RVM expects a login shell. Although using #!/bin/bash -l in your script will work, it does not seem like the best approach.
Just add this code in your shell script, i think rvm is loading from your source so it should work else need to export PATH variable
#!/bin/bash -l
source ~/.bashrc
rvm use 1.9.3#rails-3.2.3
l is for login shel, if you include x then it would be for debugging too.
adding a shebang to the build commands in jenkins fixed this for me
#!/usr/bin/env bash
rvm use 2.0.0
bundle install
rake test
...
Jenkins nodes don't load paths the same way, so it's not using the proper path to find rvm's version of ruby. You can set the path for a given agent.
Find your current PATH by doing echo $PATH
Assuming you've set up rvm properly, find where rvm's version of ruby is located by running which ruby
There's a setting in the Configuration of your agent where you can set environmental variables. Set PATH to be 1 and 2 concatenated.

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

Resources