I am new to Ubuntu!
And I am trying to setup manually Maven by adding Maven directory into $PATH. I created .bash_profile file in my home directory. The file contains this:
export PATH=/opt/devel/tools/apache-maven-3.3.3/bin:$PATHAnd then on a terminal, I run
source .bash_profileEverything works fine and I can see the version after running mvn -version. But after rebooting laptop, running mvn gets the following error:
The program 'mvn' can be found in the following packages: * maven * maven2
Try: sudo apt-get install <selected package>Could you tell me what I am missing please? Any help would be appropriate!
Edit 1
The output of echo $PATH is:
tuandang@Inspiron-N4030:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 9 3 Answers
First Please note that adding envs to the .bash_profile is not a temporary as indicated in other answer, but your problem is adding in non-suitable place since .bash_profile is called when you login from console which I don't think your case. Please Read the rest and find your solution:
Quoted from :
When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.
But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.
So as I suppose you logged in and use the terminal from inside then you should use the .bashrc instead. run this command:
echo 'export PATH=/opt/devel/tools/apache-maven-3.3.3/bin:$PATH' >>~/.bashrcThen source it:
source .bashrcFor more information please read this
If you want your variables to be used in .bash_profile also you can do this trick. Add all of your variables in .bashrc then source it from .bash_profile. Add this to your bash_profile:
if [ -f ~/.bashrc ]; then source ~/.bashrc
fiNow when you login to your system whenever it's from a console or GUI you'll get your environment.
1You can add your PATH to ~/.profile
~./bash_profile does not affect terminal emulators, like gnome-terminal, that are started after you log into system.
As an option you can setup PATH in /etc/environment globally.
6Maythux is correct, the variable was declared local, but for it to be seen as a global variable by the system it would have to be exported.
if [ -f ~/.bashrc ]; then . ~/.bashrc
fi Also works in .bash_profile to source $HOME/.bashrc
1