Reputation: 1898
Every time I log into my VPS I must run source ~/.bashrc
before I can run any rvm
, ruby
, or gem
commands.
Why is this? Can't make it load by default?
ssh deployer@xxx
ruby -v
-bash: ruby: command not found
source ~/.bashrc
ruby -v
ruby 1.9.3p429 (2013-05-15 revision 40747) [i686-linux]
I installed rvm under deployer
.
I have ~/.bash_pofile
which is empty. I also have ~/.profile
which has the following in it:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
My ~/.bashrc
has this at the top:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Upvotes: 0
Views: 3339
Reputation: 11343
Moving the information from .bashrc
to the other files, as suggested by others is one way to do it.
Otherwise, this snippet of code will do the same thing, without needing to move the contents, or remove the file. Depending on the ways you have things set up, you may not want to delete a file, if it has relevant information in it for other tasks, other than interactive login.
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Though using the files as they are intended to be used by reading the documentation can definitely alleviate some frustration.
Upvotes: 2
Reputation: 19238
When you log in, if Bash can find a file named .bash_profile
in your home directory it will execute it and do not even search for a .profile
file. Thus you have two choices, either remove the empty .bash_profile
file or copy the contents of .profile
to .bash_profile
.
Upvotes: 3
Reputation: 3545
From the bash man page:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the
--login
option, it first reads and executes commands from the file/etc/profile
, if that file exists. After reading that file, it looks for~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable.
So in your case, the (empty) ~/.bash_profile
is being executed, and your ~/.profile
(and thus your ~/.bashrc
) are ignored. To solve this, you'll either need to delete your ~/.bash_profile
, or else move the contents of ~/.profile
into ~/.bash_profile
.
Upvotes: 5