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

Answer from MrYoshiji on Stack Overflow
🌐
Medium
medium.com › @satriajanaka09 › how-to-load-rvm-in-zsh-2f3330aa5f2
How to load RVM in zsh. Recently I switch from bash to zsh + oh… | by Satria Janaka | Medium
October 5, 2021 - Turns out that’s because RVM is not loaded when I open zsh. The solution is I have to add /.rvm/scripts/rvm as my source . So, here’s what I did. I executed this command : echo "source /usr/local/rvm/scripts/rvm" >> ~/.zshrc
🌐
RVM
rvm.io › rvm › install
RVM: Ruby Version Manager - Installing RVM
Zsh not always sources /etc/profile so you might need to add this in /etc/**/zprofile: ... After following above instructions for Multi-User. Select a user as a manager - he will be responsible for installing new rubies. This user should never run the command introduced below.
🌐
GitHub
github.com › rvm › ubuntu_rvm › issues › 32
zsh:1: command not found: rvm in post-install script · Issue #32 · rvm/ubuntu_rvm
December 14, 2018 - The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect!
Author   grandchild
🌐
GitHub
github.com › rvm › rvm › issues › 2654
Better documentation on zsh integration · Issue #2654 · rvm/rvm
February 25, 2014 - 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.
Author   rebelwarrior
🌐
RVM
rvm.io › integration › zsh
RVM: Ruby Version Manager - ZSH Integration with RVM.
If you're using zsh (possibly with oh-my-zsh) and your prompt displays the current directory as "~rvm_rvmrc_cwd", the fix to add the following to your shell file before sourcing rvm:
Find elsewhere
🌐
GitHub
github.com › rvm › rvm › issues › 3845
`rvm use` fails on macOS when invoked from inside shell script · Issue #3845 · rvm/rvm
December 19, 2016 - I believe the problem is that I'm trying to execute rvm use from inside a shell script instead of directly entering in the command from a terminal? Because rvm use succeeds if directly entered in instead · Be on macOS 10.12.1, but this probably repros on other versions as well ... system: system: uname: "Darwin Andrews-MacBook-Pro.local 16.1.0 Darwin Kernel Version 16.1.0: Wed Oct 19 20:31:56 PDT 2016; root:xnu-3789.21.4~4/RELEASE_X86_64 x86_64" system: "osx/10.12/x86_64" bash: "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)" zsh: "/bin/zsh => zsh 5.2 (x86_64-apple-darwin16.0)" rvm: version: "rvm 1.28.0 (latest) by Wayne E.
Author   AndrewSB
🌐
RVM
rvm.io › support › troubleshooting
Multi-User Installs - Using the sudo command
Be sure to be using either Bash or Zsh. RVM is untested, at best, in other shells. The installation process is similar for both installation methods, however, when installing a multi-user configuration, do not run the installer directly as/from the 'root' account!
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
[SOLVED] rvm ruby problem / Newbie Corner / Arch Linux Forums
October 10, 2015 - export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting export PATH="$PATH:$HOME/.rvm/rubies/default/bin" Any help will be appreciated, and thanks for your attention... Last edited by ahmadelmorshedy (2015-11-07 15:45:01) ... Ok... I finally found what the probleem was... I installed zsh and using oh my zsh, it's configured to be my terminal, all i need to do was to edit ~./zshrc instead of ~/.bashrc file
Top answer
1 of 2
2

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.

2 of 2
0

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