iTerm2 Setup as Login Shell, RVM Still Gives Error - ruby

I have been trying to install Ruby-2.6.1 on my Macbook Pro for a couple of days now, and I have followed many posts and blog posts to try to get the setup correct, but I am not successful. I always get the following when trying to set the default Ruby with RVM:
picklemac:~ jblanchard$ rvm use default ruby-2.6.1
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.
I have followed the link, but with no success. I have iTerm2 setup as a login shell:
In .bashrc I have the following:
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
And in .bash_profile I have the following:
# rvm
# export PATH="/Users/jblanchard/.rvm/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
As I said, I have read and tried a number of things to get iTerm2 and my Mac setup properly, including How to make zsh run as a login shell on Mac OS X (in iTerm)?. Also, because I am trying to upgrade from Ruby 2.3 I have read a number of posts on just how to do that - again with no success.
What am I doing wrong?
Additional Info
I am able to successfully list the installations using rvm list:
picklemac:~ jblanchard$ rvm list
ruby-2.6.0 [ x86_64 ]
=* ruby-2.6.1 [ x86_64 ]
# => - current
# =* - current && default
# * - default
This is interesting, because RVM indicates Ruby-2.6.1 is the default, but when I use ruby -v the return is:
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]

I was able to successfully make the change to Ruby-2.6.1. First, I uncommented the export line in .bash_profile:
# rvm
export PATH="/Users/jblanchard/.rvm/bin:$PATH" #UNCOMMENTED
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
After stopping and starting iTerm2 I issued the command to use Ruby-2.6.1 and received a warning, but then:
picklemac:~ jblanchard$ rvm use default ruby-2.6.1
Warning! PATH is not properly set up, /Users/jblanchard/.rvm/gems/ruby-2.6.1/bin is not at first place.
Usually this is caused by shell initialization files. Search for PATH=... entries.
You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
To fix it temporarily in this shell session run: rvm use ruby-2.6.1
To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
Using /Users/jblanchard/.rvm/gems/ruby-2.6.1
The change to Ruby-2.6.1 was made. It appears I do need to run rvm get stable --auto-dotfiles to fix the warning, which I would prefer to silencing it. Now, when running ruby -v the return is:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]

Related

Error about ruby & rvm default version

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

"bash: rvm: command not found" after multi-user install

I have followed the instructions of how to do a multi-user install of rvm on Ubuntu. I did not do this as root. When i do "source /etc/profile.d/rvm.sh" then I can use rvm. However if I log out and log in again and do "rvm -v" I get "bash: rvm: command not found". Can I make it so that I don't have to write "source /etc/profile.d/rvm.sh"?
As non-root user by the name of "user1" I did:
# multi-user install
\curl -sSL https://get.rvm.io | sudo bash -s stable
# add user1 to rvm group
sudo adduser user1 rvm
source /etc/profile.d/rvm.sh
Then I exit the shell and start a new one:
user1#72265e666e07:/$ rvm -v
bash: rvm: command not found
Look at answers for this question:
From your problem description it seems that the rvm script needs to be
loaded only once, during login. As far as I know, Ubuntu reads
/etc/profile/ and ~/.profile during login (the graphical login,
independent of bash). That means, after logging out and a logging in
once, the rvm script should be active. If it still doesn't work, then
perhaps the rvm script needs to be loaded for every bash session. If
that is the case then bashrc is the more appropriate place for the
script.
The problem for me was that rvm was not in any of my bash init files. I thought that that should be installed/configured automatically when installing rvm, but apparently it was not!
I had to run the two following commands to add rvm initialization globally for every user.
printf '\n\nif [ -s "$HOME/.rvm/scripts/rvm" ] ; then\n . "$HOME/.rvm/scripts/rvm"\nelif [ -s "/usr/local/rvm/scripts/rvm" ] ; then\n . "/usr/local/rvm/scripts/rvm"\nfi' >> /etc/profile
printf '\n\nif [ -s "$HOME/.rvm/scripts/rvm" ] ; then\n . "$HOME/.rvm/scripts/rvm"\nelif [ -s "/usr/local/rvm/scripts/rvm" ] ; then\n . "/usr/local/rvm/scripts/rvm"\nfi' >> /etc/bash.bashrc
After I had run these two commands it is possible to reach rvm directly when I log in to my user "user1".

RVM is not a function even when running command as login shell [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Cannot use RVM-installed Ruby with sudo
I'm running into the same "RVM is not a function..." error when executing the command sudo rvm use 1.9.3 as everyone else, but try as I might, I cannot seem to resolve it. I've read and followed through with all of the common troubleshooting tips, but nothing seems to work...
My System --- OS: Ubuntu 12.10 --- Ruby Version: 1.9.3 --- RVM Version: 1.18.3
I have done the following to try to repair the issue:
Checked the 'Run command as login shell' option in the "Title and Command" tab for Terminal preferences
Added the following code block to ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.zprofile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi`
Running user$ source ~/.rvm/scripts/rvm and then user$ type rvm | head -n 1 DOES return rvm is a function. But then running sudo rvm use 1.9.3 returns "RVM is not a function"
What else can I do to resolve this issue?
You can not run rvm with sudo, sudo is running a new process which defeats the function approach which can change current running shell environment.

How do I change my Ruby version using RVM?

I am not able to switch the current Ruby version:
➜ ~ rvm list
rvm rubies
ruby-1.9.2-p290 [ x86_64 ]
ruby-1.9.3-p0 [ x86_64 ]
➜ ~ rvm use ruby-1.9.3-p0
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Fixed it. I needed to add:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM
to .zshrc
This happened to me too. I had:
export PATH=~/.rvm/bin:$PATH
Added in my .bashrc.
All I had to do was add another
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
to the same file and it worked!
Of course, you have to restart your terminal after that.
Your shell doesn't know about the RVM function. After you install it, it tells you how to take care of this. Or go to the install page on the RVM site and check out the section titled "2. Load RVM into your shell sessions as a function"
Run this once to add the line that loads rvm into your ~/.bash_profile:
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
or manually add it yourself. (Note that on some systems, you will want to put it in other places, for example on my system, Mac OSX Lion, I put it in ~/.profile)
(Kubuntu 11.10) The ~/.bash_profile is now called ~/.profile
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.profile
source ~/.profile
rvm info # And now the fields display
To Change the Default Version of ruby:
In Ubuntu 11.10
please change your GNOME terminal setting :
Go to Terminal and then follow the following instructions:
1. Edit > Profile Preferences
2. Open Title and Command Tab
3. Check Run Command as a login Shell
4. Restart terminal
Run this command on terminal:
rvm --default use ruby_Version
To add all RVM functionality to your .bash_profile you should use following command:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
After that you should reload the current shell or open a new terminal session and type the following command to reload .bash_profile:
source .bash_profile
The above solution will only work, if RVM is installed for the current user. A more general solution would use the RVM path variable:
# The following code loads RVM as user or system install:
[[ -s "$rvm_path/scripts/rvm" ]] && . "$rvm_path/scripts/rvm"
I just had to invoke source ~/.bash_profile
On a clean install of Ubuntu 12.04 I ran into the same issue. The RVM installer creates or appends to a file called ~/.bash_login the necessary bit of code to avoid the original problem:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
However this does not seem to get invoked. Adding it to ~/.bashrc resolved the issue for me.
Installing RVM, See here http://octopress.org/docs/setup/rvm/
In my case on Ubuntu, the entry in ~/.bashrc had:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && ."$HOME/.rvm/scripts/rvm" # BAD
instead of:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # WORKING
Notice the missing space between . and "$HOME.
Also, if this is the problem, you should also be noticing an error on top when you start your terminal.
I had a global install of RVM, which runs /etc/profile.d/rvm.sh. However, that script requires the BASH_VERSION or ZSH_VERSION to be set. I was running from crontab, which uses "sh".
I created a wrapper script that uses /bin/bash to source /etc/profile.d/rvm.sh.
You need to change your terminal emulator preferences to allow login
shell. Sometimes it is required to use /bin/bash --login as the
command.

RVM system-wide install script url broken -- what is replacement?

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'"

Resources