Bash: Switching from user to root causes issues with prompt

Option 1

Use sudo su - instead of just sudo su

The extra dash is a synonym for -l which simulates a full login. This means it will read config files (.bashrc, .profile, etc) from the root user's home directory.

Option 2

If you insist on using your own .bashrc, put a test in to check for the existence of RVM in the path before trying to put it in the path. Something like this:

type rvm > /dev/null
RVM_EXISTS=$?  # get exit status, 0 if it exists
if [ $RVM_EXISTS ] 
then
    PS1=(your rvm code here)
else
    PS1=(your prompt w/o rvm here)
fi

(not tested)

Option 3

Test for existence of rvm as in option 2, but create a dummy rvm bash function if it doesn't exist and don't alter PS1

type rvm > /dev/null
RVM_EXISTS=$?  # get exit status, 0 if it exists
if [ ! $RVM_EXISTS ] 
then
   rvm () { echo > /dev/null }
fi