Fish shell and rvm - allowing login shell - bash

When I try to use rvm in fish shell, I get this message:
ciembor#ciembor ~> rvm use 1.9.2
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 a
example.
I get used to use /bin/bash --login, then rvm and then starting fish from bash. But isn't there more straightforward way? I use xfce4 terminal.

I had the same issue. Download the rvm fish function from GitHub:
curl --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish
Reference: http://rvm.io/integration/fish

Download the fish functions from GitHub.
curl -L --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish
And activate the default Ruby manually in your config.fish file:
echo "rvm default" >> ~/.config/fish/config.fish
And you're done

Try look at bash "initialization" files like ~/.bashrc ~/.bash_profile and session "initialization" files ~/.profile /etc/profile* and add rvm related code(something like
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
) to fish "initialization" file ~/.config/fish/config.fish

Related

Automatic RVM installation

I am trying to have RVM and ruby installed in an Ubuntu 12 virtual machine without human interaction apart from the password prompts.
I created a shell script to do this that works pretty fine until I need to use RVM itself.
I am using multi-user installation.
#!/bin/bash -l
mainUser=`whoami`
echo "Installing as '${mainUser}'"
echo "Installing git..."
sudo -S apt-get install --yes curl git-core
echo "Installing RVM..."
\curl -L https://get.rvm.io | sudo bash -s stable
echo "Adding ${mainuser} to RVM group..."
sudo adduser $mainUser rvm
newgrp rvm
From here things get weird.. I need to load dvm as a source. I want both my script to have this source and my user's bash_profile / bashrc. Anyway.. I know how to do it manually, but I can't have this done from the script. This is the last code I tried:
. "/usr/local/rvm/bin/rvm"
rvm use ruby-head
rubyVersion=`rvm list | awk '/ruby-head/{print x;print};{x=$0}' | sed -n '/ruby-head/{g;1!p;};h' | awk -F ' ' '{print $1}'`
rubyTest=${rubyVersion}#test
rvm use $rubyTest --create --default
The error I get is this:
test.sh: 7: /usr/local/rvm/bin/rvm: Syntax error: "(" unexpected (expecting "fi")
If I simply try to use the full path, like this:
rvm=/usr/local/rvm/bin/rvm
$rvm use ruby-head
rubyVersion=`$rvm list | awk '/ruby-head/{print x;print};{x=$0}' | sed -n '/ruby-head/{g;1!p;};h' | awk -F ' ' '{print $1}'`
rubyTest =${rubyVersion}#test
$rvm use $rubyTest --create --default
I get this error instead:
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
I am clueless. Why can't I use /usr/local/rvm/bin/rvm?
Is there a way to execute source /etc/profile.d/rvm.sh for this user from the script?
I am not so good at shell script and Linux, so I appreciate any references and examples you could give.
Thanks!
UPDATE
I also tried:
source "/usr/local/rvm/scripts/rvm"
... and all it's variants. Same error: "RVM is not a function".
rvm is actually implemented as a shell function rather than an executable, which is why you can't just call /usr/local/rvm/bin/rvm itself.
Quoting you, "Is there a way to execute source /etc/profile.d/rvm.sh for this user from the script?"
Have you tried doing that? I had a somewhat similar install once where it didn't work properly from crontab (they have instructions on the site for that scenario, but we couldn't make them work), and I had to do almost exactly that -- source part of the profile.d for rvm.
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Above error is generated when rvm is not running and hence your terminal is not able to recognize it, as it tries to run it as a system command.
You may want to try this to run rvm through your shell script before calling rvm methods:
source ~/.rvm/scripts/rvm
I found out what is causing the issue.
I realised before that I would get errors in the lines with conditions in the script files, so I came across this page:
https://superuser.com/questions/552016/bash-script-not-found
As it happens, I was executing the script with the following command:
sh script.sh
Which means I was getting Dash instead of Bash.
To fix the issue I changed my code to have this:
PATH=$PATH:/usr/local/rvm/bin # Add RVM to PATH for scripting
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function
And then I executed like this:
bash script.sh
And voilà... RVM works again!

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

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.

Is there a way to fix this error in terminal: -bash: HOME/.rvm/scripts/rvm: No such file or directory?

I'm new to Ruby and just installed it following the instructions on this website.
I'm not sure why, but now whenever I open terminal, I get the following error message:
-bash: HOME/.rvm/scripts/rvm: No such file or directory
Is there something I'm missing? As far as I can tell, Ruby is installed correctly and is running fine.
It looks like you put HOME in your .bash_profile instead of $HOME. You should also verify that your .rvm directory exists in your home directory. You could also check the value of $HOME by running echo $HOME in a shell, and it should return something like /home/yourname.
Note: You could change "$HOME" to "~".
This maybe solve your problem:
Before you install RVM, you can input this in your terminal to check server key:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Then you can input the following command to install rvm
curl -L https://get.rvm.io | bash -s stable
Just have a try~
You must source the rvm scripts so that they are available to your terminal session
source /usr/local/rvm/scripts/rvm
source ~/.rvm/scripts/rvm
You may want to add it to your .bash_profile or .bashrc file so that they are executed every time you load a terminal window like so:
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> .bashrc

RVM is not working over SSH

RVM is not working over SSH.
At the command-line:
leifg#host:~$ which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby
Connected over SSH:
local:~$ ssh leifg#server 'which ruby'
/usr/bin/ruby
I'm using Ubuntu 11.04.
How do I get SSH to use the same Ruby as it is on the system?
I already verified some prequisites:
Ruby was already installed using apt-get install ruby. Does that make any difference?
sshd_config has the option "PermitUserEnvironment yes", and I restarted the daemon.
The .bashrc on the server contains these lines, but I see the same behavior when I remove them:
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
Actually, your ~/.bashrc will be executed. The problem is usually that one adds the
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
... snippet at the bottom of the file. However, the default .bashrc on ubuntu systems includes the following near the top
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
That call will stop executing the rest of the script and will therefore not set the proper paths. So you can either put the rvm call at the top of the file or remove the return call.
From the ssh man page:
If command is specified, it is executed on the remote host instead of
a login shell.
This should mean that your .bashrc won't get sourced, so RVM doesn't get set up.
Solution
This did the trick in the end:
ssh <host> bash --login -c <command>
Start bash as a login shell through SSH and then start the RVM installed Ruby via SSH's -c option.
Actually there's totally another, more safe and lightweight option.
You add "PermitUserEnvironment yes" somewhere to your sshd_config in /etc/(open)ssh
Now you are allowed to specify user environment in /home/user/.ssh/environment. So what do you put there ?
Just something like :
user# env | grep rvm > ~/.ssh/environment
so it looks like below :
user#app3:~$ cat ~/.ssh/environment
rvm_bin_path=/usr/local/rvm/bin
GEM_HOME=/usr/local/rvm/gems/ree-1.8.7-2012.02
IRBRC=/usr/local/rvm/rubies/ree-1.8.7-2012.02/.irbrc
MY_RUBY_HOME=/usr/local/rvm/rubies/ree-1.8.7-2012.02
rvm_path=/usr/local/rvm
rvm_prefix=/usr/local
PATH=/usr/local/rvm/gems/ree-1.8.7-2012.02/bin:/usr/local/rvm/gems/ree-1.8.7-2012.02#global/bin:/usr/local/rvm/rubies/ree-1.8.7-2012.02/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
rvm_version=1.14.5 (stable)
GEM_PATH=/usr/local/rvm/gems/ree-1.8.7-2012.02:/usr/local/rvm/gems/ree-1.8.7-2012.02#global
Note: this also works work user-install RVM (not only for the system wide)
Now your are able to use ruby in ssh non interactive sessions :
ssh user#app3 'ruby --version'
ruby 1.8.7 (2012-02-08 MBARI 8/0x6770 on patchlevel 358) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2012.02
Voila!
“rvm” has two invocation bugs: the default installation drops the file /etc/profile.d/rvm.sh and believes any bash trick is now globally available. – This assumption is wrong.
Files in /etc/profile.d/ are “sourced” on login, but maybe not from bash, maybe not even from a shell. So the cd hook it installs is not there after the shell which runs these files exits. Actually, because of the buggy way “rvm” installs this hook, it is already gone once you run naked bash in a login-shell!
I don’t know if “rvm” supports an explicit invocation for virtual environments, without relying on cding into some directory (that I consider the second bug).
There is one sane workaround:
Make your shell source /etc/profile.d/rvm.sh from e.g. ~/.bashrc. .bashrc is executed from any non-login bash, and login-bash is usually setup to source .bashrc from those login-shell files like ~/.profile
For your ssh problem: should a proper ssh-shell not be login-shell anyway?
I've just added at the top of ~/.bashrc (for git user) this string:
[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"
Mentioned solutions work certainly fine, but mine was to run
source /usr/local/rvm/environments/<ruby version>#<gemset version>
at the start of the remote ssh call. Something like:
ssh -l <remote username> <server ip> "source /usr/local/rvm/environments/<ruby version>#<gemset version> ; <rest of the remote script>"
(if using Capistrano) Don't use rvm1/capistrano3 or rvm/capistrano; don't set :pty.
Change ~/.rvmrc for the runner user, on the server, to this — note that it has to come before the line where it kills itself when not running interactively:
# get rvm for non-interactive shells (eg capistrano) too
source /etc/profile.d/rvm.sh
export BASH_ENV=$HOME/.bashrc
export rvm_is_not_a_shell_function=0
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
I had the same problem. I realized, that I accidentally installed RVM for multiple users, too. After deleting the directory /usr/local/rvm and edit ~/.bashrc like zoonmix suggested, the problem was solved.
Make sure that on the server you have done something like rvm --default 1.9.2 to set RVM's Ruby to be the default. Otherwise, it will always use the default system Ruby.
zoomix's is the best solution. But when you change with "ruby rvm use system" in terminal or what else you get an error :
Warning! PATH is not properly set up, is not at first place.... To solve that put the snippet just before the return instead of at the top of the .bashrc file (Debian Jessie here)
case $- in
*i*) ;;
*)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
return;; esac

Resources