Possible duplicate of: Ubuntu rvm setup issue
Your problem is that RVM is not loaded when you open a new terminal.
To solve this, run this command line: (if using login-shell)
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
Or this (if using non-login shell):
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
Or if you are using zsh (and/or oh-my-zsh):
echo "source $HOME/.rvm/scripts/rvm" >> ~/.zshrc
This will add the path to RVM to load at each Terminal instantiation. You must either close and reopen your terminals or simply call source ~/.bashrc (or ~/.bash_profile or ~/.zshrc).
Possible duplicate of: Ubuntu rvm setup issue
Your problem is that RVM is not loaded when you open a new terminal.
To solve this, run this command line: (if using login-shell)
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
Or this (if using non-login shell):
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
Or if you are using zsh (and/or oh-my-zsh):
echo "source $HOME/.rvm/scripts/rvm" >> ~/.zshrc
This will add the path to RVM to load at each Terminal instantiation. You must either close and reopen your terminals or simply call source ~/.bashrc (or ~/.bash_profile or ~/.zshrc).
I had this problem after installing zsh. I'm a domain user so my $PATH and $HOME are not as straight-forward. What worked for me was
echo "source /usr/share/rvm/scripts/rvm" >> ~/.zshrc
Make an alias to rvm-prompt. That's the most sure-fire answer. Arrange things in your .zshrc file in this order:
alias rvm-prompt=$HOME/.rvm/bin/rvm-promptsource $ZSH/oh-my-zsh.sh[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
If oh-my-zsh (OMZ) loads before RVM, which rvm-prompt fails silently, so you won't see RVM in your prompt (if supported by your theme) even though it is in your path later, after RVM loads.
If RVM loads before OMZ, you may get a zsh: command not found: rvm-prompt.
Aliasing your rvm-prompt to its actual location seems to solve the problem, regardless of which order RVM and OMZ are loaded in. I'd still recommend RVM at the bottom.
Putting the RVM load into .zshenv as suggested above would load RVM twice in iTerm 2 (and no, it was not still in my .zshrc) and would result in the prompt displaying "system" even though rvm-prompt and rvm current showed a specific ruby version and gemset.
I had the same problem until I put [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" into a .zshenv file instead of the .zshrc file.
Do you have this line in your ~/.zshrc?
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
Note March 2014:
With latest RVM, the following line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
isn't needed anymore, and it shouldn't be in your ~/.zshrc.
Documentation has been updated in RVM documentation with Zsh:
Make sure in iTerm2 Preferences: Login shell option is set (do not use Command option). This is required for RVM to work.
If you are still getting rvm is not a function errors on iTerm, try:
rvm get stable --auto-dotfiles
It might because the terminal not having rvm shell configuration loaded.
Try following from your terminal:
$ source ~/.rvm/scripts/rvm
then
$ type rvm | head -n 1
If the output is:
rvm is a function
You may need to add "source ~/.rvm/scripts/rvm" to your ~/.bash_profile file
you need to read all the texts that are displayed when you install RVM:
rm -rf ~/.rvm
curl -L https://get.rvm.io | bash -s stable
The problem is that the commands rvm and rvmsudo are not in your PATH. The PATH is a variable that lists all of the directories that are searched for commands.
You need to find out where the rvm and rvmsudo commands are actually located; it could be in /usr/local somewhere or in /opt. If the RVM software was installed in /usr/local I would guess that it would work just fine; check /opt.
Then add the directories that contain commands to your PATH (on the command line and in .profile):
export PATH=$PATH:/opt/rvm/bin:/opt/rvm/sbin
(The directories are just examples.) Using $PATH preserves your current PATH and adds the two new directories on the end. Directories are searched from left to right and are separated by :.
More on this can be found in man bash or man sh or man ksh depending on your shell.
On Ubuntu you need to use ~/.bashrc instead of ~/.bash_profile in case if per user installations, So do:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
or if you're using ubuntu 12.04:
echo '[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
and after that:
source ~/.bashrc
and test with:
type rvm | head -1
you should get: rvm is a function
Installing zsh doesn't install Oh My Zsh, which might explain if you don't have an oh-my-zsh.sh file at all (this was the case for me).
You can install Oh My Zsh by running
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
For this:
/Users/jack/.zshrc:source:34: no such file or directory: /Users/jack/.oh-my-zsh/oh-my-zsh.sh
The problem is this line:
source $ZSH/oh-my-zsh.sh
You don't have a file called oh-my-zsh.sh in /Users/jack/.oh-my-zsh
For this:
/Users/jack/.zshrc:source:38: no such file or directory: .bashrc
The problem is the same as above; essentially, you don't have .bashrc file in /Users/jack/
Your $ZSH is pointing to /Users/jack/.oh-my-zsh and it looks like there's no such file in that directory with the name zsh.sh
As far as the initial problem (zsh: command not found: rvm) the issue is that the command rvm is not located anywhere in your $PATH which apparently points to /usr/local/bin plus whatever the system-wide setting is.
I recommend you use find / -name "rvm" and see where in the file system is rvm really located and then update your $PATH variable as so: export PATH=/path/to/rv/:$PATH
It seems that you are using a theme which uses rvm-prompt like "fino-time".
from the looks of it, you might be calling that command from your prompt definition.
Your .zshrc or .zshenv is likely sourcing $HOME/.rvm/scripts/rvm (which you do not want to do anymore, now that you removed it from your system)
What went wrong?
During installation, rvm puts two lines (first one is a comment though) in ~/.bash_profile file to help bash recognize ruby binaries. But the problem is Ubuntu's bash ignores this file. As a result, it doesn't know that you already installed ruby and prompts you to install ruby!
The problem can be solved in two different way.
Solution 1: Using ~/.bashrc file
Open your ~/.bashrc file and put these two lines (or last one) there.
### Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Solution 2: Make the regular shell session as login shell
Or you can turn on your virtual terminal's preference to consider the shell as Login Shell. The settings can be found in -
Gnome Terminal: Menu > Edit > Profile Preference > Command Tab > Run command as a login shell
Mate Terminal: Menu > Edit > Profile Preference > Title & Command Tab > Run command as a login shell
Xfce4 Terminal: Menu > Edit > Preference > General Tab > Run command as login shell
Either one will do the job.
Another solution could be installing Ruby in System using Ubuntu's repository. But that defeats the purpose of using rvm at first place.
You can install Ruby by typing:
sudo apt-get install ruby-full
See the Doc.
For me, I just had to add
source $HOME/.rvm/scripts/rvm
to my ~/.zshrc and it started working, after having the same error message as in this SO question.
Turns out that RVM was installed in the wrong place. When I had initially installed RVM I believe I did so with the sudo command, which ran the multi-user install (installed to /usr/local/rvm), and not the single user (should be in ~/.rvm/scrips/rvm), which is why all the posted solutions were not working for me.
I had to uninstall RVM with rvm implode. There were some permissions issues, so I had to manually go in and delete the files that could not be deleted. Ran the curl command to re-install RVM and now it's installed in the correct place.
Sourcing RVM in my .zshrc with [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" now works properly and I can switch between rubies.
check your rc files
- .zshenv
- .zshrc
- .zlogin
- .zprofile
most likely in one of those PATH is reset after RVM was sourced
also some oh-my-zsh plugins can break stuff, try disabling them and enabling one by one.
In my case, this was related to ZSH complains about RVM __rvm_cleanse_variables: function definition file not found , and following the instructions there solved it.
After quite a bit of tinkering, rvm finally successfully loads its environment by default. Now, I don't know exactly what part of what I did fixed the issue, but hopefully, this will be of aid to someone.
Essentially, I went through and split up my zsh configuration into two files: the .zshenv file (which gets loaded by all programs) and the .zshrc file (which gets loaded by graphical programs). For those unfamiliar with how zsh works, these files are essentially analogs to .bash_profile and .bashrc.
My .zshenv:
# -------------------------------------------------------------
# Maintainer: Itai Ferber
# http://itaiferber.net - [email protected]
#
# Version: 1.0 - 19/02/12
#
# Sections:
# -> RVM
# -> Environment Variables
# -> Aliases
# -> File Manipulation
# -> Process Manipulation
# -> Terminal Manipulation
# -> zsh Options
#
# Revisions:
# -> 1.0.0: Initial revision (settings copied over from .zshrc where logical).
# -------------------------------------------------------------
# -------------------------------------------------------------
# => RVM
# -------------------------------------------------------------
[[ -s ~/.rvm/scripts/rvm ]] && source ~/.rvm/scripts/rvm
# -------------------------------------------------------------
# => Environment Variables
# -------------------------------------------------------------
# Path
export PATH=.:~/.rvm/bin:/usr/local/bin:/usr/local/sbin:~/Library/Haskell/bin:/usr/local/texlive/2011/bin/universal-darwin:/usr/local/narwhal/bin:$PATH
# History
export HISTFILE=~/dotfiles/.zsh_history
export HISTSIZE=10000
export HISTCONTROL=ignoredups
export SAVEHIST=10000
# Editor
export EDITOR=vim
# Localization
export LC_TYPE=en_US.UTF-8
# Frameworks
export NODE_PATH=/usr/local/lib/node/:$NODE_PATH
export CAPP_BUILD='/Users/itaiferber/Desktop/Cappuccino Build'
export NARWHAL_ENGINE=jsc
# -------------------------------------------------------------
# => Aliases
# -------------------------------------------------------------
# Command Aliases
alias ..='cd ..'
alias ...='cd ../..'
alias internet='lsof -inP | cut -f 1 -d " " | uniq'
alias restart='sudo shutdown -r NOW'
# Expansions
alias ls='ls -AFGp'
alias tree='tree -aCFl --charset=UTF8 --du --si'
# Root Aliases
[ $UID = 0 ] && \
alias rm='rm -i' && \
alias mv='mv -i' && \
alias cp='cp -i'
# -------------------------------------------------------------
# => Terminal Manipulation
# -------------------------------------------------------------
# Usage: reset
# Description: 'resets' the terminal by clearing and returning to default directory
reset () {
cd ~/Desktop && clear
}
# -------------------------------------------------------------
# => Process Manipulation
# -------------------------------------------------------------
# Usage: pid <procname>
# Description: returns the pid of the process with the given name
# Notes: if multiple processes with the given name are running, no guarantee is made to which pid is returned
pid () {
ps Ao pid,comm | grep -im1 $1 | awk '{match($0,/([0-9]+)/); print substr($0,RSTART,RLENGTH);}'
}
# Usage: fp <pattern>
# Description: list processes matching the given partial-match pattern
fp () {
ps Ao pid,comm | awk '{match($0,/[^\/]+$/); print substr($0,RSTART,RLENGTH)": "$1}' | grep -i $1 | grep -v grep
}
# Usage: fk <pattern>
# Description: list process matching the given partial-match pattern to kill
fk () {
IFS=$'\n'
PS3='Kill which process? (1 to cancel): '
select OPT in 'Cancel' $(fp $1); do
if [ $OPT != 'Cancel' ]; then
kill $(echo $OPT | awk '{print $NF}')
fi
break
done
unset IFS
unset PS3
}
# Usage: console <procname>
# Description: get the latest logs for the given process name
console () {
if [[ $# > 0 ]]; then
query=$(echo "$*" | tr - s ' ' '|')
tail -f /var/log/system.log | grep -i --color=auto -E "$query"
else
tail -f /var/log/system.log
fi
}
# -------------------------------------------------------------
# => File Manipulation
# -------------------------------------------------------------
# Usage: rm <file>
# Description: if called with no arguments, move files to trash instead of deleting outright
rm () {
local path
for path in "$@"; do
if [[ "$path" = -* ]]; then
/bin/rm $@
break
else
local file=${path##*/}
while [ -e ~/.Trash/"$file" ]; do
file="$file "$(date +%H-%M-%S)
done
/bin/mv "$path" ~/.Trash/"$file"
fi
done
}
# Usage: extract <file>
# Description: extracts archived files / mounts disk images
extract () {
if [ -f $1 ]; then
case $1 in
*.bz2) bunzip2 $1;;
*.dmg) hdiutil mount $1;;
*.gz) gunzip $1;;
*.tar) tar -xvf $1;;
*.tar.bz2|*.tbz2) tar -jxvf $1;;
*.tar.gz|*.tgz) tar -zxvf $1;;
*.zip) unzip $1;;
*.Z) uncompress $1;;
*) echo "'$1' not recognized.";;
esac
else
echo "'$1' not found."
fi
}
# -------------------------------------------------------------
# => zsh Options
# -------------------------------------------------------------
# Directories
setopt AUTO_CD AUTO_PUSHD CD_ABLE_VARS CHASE_DOTS CHASE_LINKS
# Completion
setopt AUTO_LIST AUTO_MENU AUTO_PARAM_SLASH COMPLETE_IN_WORD LIST_TYPES MENU_COMPLETE REC_EXACT
# History
setopt APPEND_HISTORY EXTENDED_HISTORY
# Input/Output
setopt CORRECT
# Scripts and Functions
setopt MULTIOS
# Other
setopt NO_BEEP ZLE
# Key Bindings
bindkey "^[[3~" delete-char
My .zshrc:
# -------------------------------------------------------------
# Maintainer: Itai Ferber
# http://itaiferber.net - [email protected]
#
# Version: 1.0 - 19/02/12
#
# Sections:
# -> zshenv
# -> screen
# -> Environment Variables
# -> Prompt
# -> zsh Autocompletion
#
# Revisions:
# -> 1.0.0: Initial revision. Style copied from vimrc.
# -------------------------------------------------------------
# -------------------------------------------------------------
# => zshenv
# -------------------------------------------------------------
source ~/.zshenv
# -------------------------------------------------------------
# => screen
# -------------------------------------------------------------
if [[ $TERM != 'screen' ]]; then
exec screen -aADRU
fi
reset
# -------------------------------------------------------------
# => Environment Variables
# -------------------------------------------------------------
export TERM=xterm-256color
export CLICOLOR=AxFxcxdxBxegbdHbGgcdBd
# -------------------------------------------------------------
# => Prompt
# -------------------------------------------------------------
if [[ $UID = 0 ]]; then
export PROMPT="%~ +=> "
else
export PROMPT="%~ => "
fi
export RPROMPT="%*"
# -------------------------------------------------------------
# => zsh Autocompletion
# -------------------------------------------------------------
# Enable autocompletion.
autoload -U compinit && compinit -C && autoload -U zstyle+
# Attempt to complete as much as possible.
zstyle ':completion:*' completer _complete _list _oldlist _expand _ignored _match _correct
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
# Sort files by name.
zstyle ':completion:*' file-sort name
# Allow for case-insensitive completion.
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
# Color completions.
zstyle ':completion:*' list-colors ${CLICOLOR}
zstyle ':completion:*:*:kill:*:processes' command 'ps -axco pid,user,command'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
# Set the amount of completions that triggers the menu.
zstyle ':completion:*' menu select=long
# Ignore certain patterns.
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.(o|c~|old|pro|zwc)'
# Cache completions.
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zcompcache/$HOST
# Allow errors.
zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
# Insert all expansions for expand completer (eh, don't know what this does).
zstyle ':completion:*:expand:*' tag-order all-expansions
# Formatting and messages.
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''
# Offer indexes before parameters in subscripts.
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
Hopefully, this can serve as a little guide to tip off anyone else having the same problems I did.
This is a huge hack, but I just put this line into .bashrc as well as in .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
With this, rvm use 1.93 and similar commands worked at both normal and screen prompts, no longer giving the rvm is not a function error. As long as this snippet is idempotent (i.e. has no ill effects due to being invoked twice or N times) this should be ok. And given that it is invoked on every login shell anyway, that is probably true. But let's see if that is the case...