~/.bash_profile
is only sourced by bash when started in login mode. That is typically when you log in at the console (Ctrl+Alt+F1..F6), connect via ssh, or use sudo -i
or su -
to run commands as another user.
When you log in graphically, ~/.profile
will be specifically sourced by the script that launches gnome-session (or whichever desktop environment you're using). So ~/.bash_profile
is not sourced at all when you log in graphically.
When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc
.
The right place for you to put these environment variables is in ~/.profile
, and the effect should be apparent next time you log in.
Sourcing ~/.bash_profile
from ~/.bashrc
is the wrong solution. It's supposed to be the other way around; ~/.bash_profile
should source ~/.bashrc
.
See DotFiles for a more thorough explanation, including some history of why it is like it is.
(On a side note, when installing openjdk via apt, symlinks should be set up by the package, so that you don't really need to set JAVA_HOME
or change PATH
)
There are 2 possible solutions:
1. Correct the $PATH
statement manually:
You have made an error in your ~/.profile
file which accounts for anaconda not being in your $PATH
. Your have added here:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH:/home/ofirarzi/anaconda3/bin" <-------
fi
which is incorrect as the conditional statement tests for the directory $HOME/bin
and if this is not present the extra $PATH
will be ignored. In your case I suspect you do not have a $HOME/bin
...
Try the following instead (leaving preceding lines of ~/.profile
untouched):
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
export PATH=/home/ofirarzi/anaconda3/bin:$PATH
Note that the new anaconda $PATH
is prepended rather than appended as explained in this post. Then test by running the following two commands:
source ~/.profile
echo $PATH
And now all should be well, if not:
2. Allow the installer to correct the $PATH
:
If there is still some trouble I note that the anaconda installer offers to make the required changes for you. I installed on Xenial and saw the following offer at the end of installation (the arrows are my addition):
creating default environment...
installation finished.
Do you wish the installer to prepend the Anaconda2 install location
to PATH in your /home/andrew/.bashrc ? [yes|no] <-----
[no] >>> yes <-----
Prepending PATH=/home/andrew/anaconda2/bin to PATH in /home/andrew/.bashrc
A backup will be made to: /home/andrew/.bashrc-anaconda2.bak
For this change to become active, you have to open a new terminal.
Thank you for installing Anaconda2!
Share your notebooks and packages on Anaconda Cloud!
Sign up for free: https://anaconda.org
andrew@athens:~$
And on my Xenial system typing 'yes' added the following to ~/.bashrc
:
# added by Anaconda2 4.1.1 installer
export PATH="/home/andrew/anaconda2/bin:$PATH"
So a re-installation of anaconda is another option, allowing the installer to do the hard work :)
Best Answer
Ubuntu does not normally have a
.bash_profile
You should add your change to the end of
.profile
instead, since this file will not be read if.bash_profile
exists, and Ubuntu normally has code in.profile
to at least source.bashrc
in login shells, so we want it to be read!I recommend you don't create any new files, but modify the existing
.profile
(found in your home directory, but hidden as it starts with a.
) instead to add to your PATH. This is an appropriate and usual way of modifying your environment in Ubuntu