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:$PATH

And then on a terminal, I run

source .bash_profile

Everything 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

  • Check this thread $PATH.
    – vembutech
    Jun 8 '15 at 13:53
  • Thank you! But my case hasn't maven 2 setting up before
    – Tuan
    Jun 8 '15 at 14:46
  • Also add cat ~/.bash_profile. Where did you create it? It is not /home. It is /home/$USER
    – Pilot6
    Jun 8 '15 at 15:41
  • @Pilot6 It's in home directory. The command shows that export PATH="/opt/devel/tools/apache-maven-3.3.3/bin:$PATH"
    – Tuan
    Jun 8 '15 at 15:49
  • 2
    .bash_profile is used when login in via console not using terminal, you have to use .bashrc instead. check my asnwer.
    – Maythux
    Jun 8 '15 at 16:00

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 http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html:

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' >>~/.bashrc

Then source it:

source .bashrc

For 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

Now when you login to your system whenever it's from a console or GUI you'll get your environment.


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

  • Thanks for detail guide. I tried with /etc/environment before and it worked. But now I want to set with ~/.bash_profile. My desktop in office also set in .bash_profilefile and it's working. So I don't think the PATH only is temporarily
    – Tuan
    Jun 8 '15 at 14:44
  • You are correct. I missed that you added to .bash_profile. I saw only export command. Why don't you add to your question output of echo $PATH?
    – Pilot6
    Jun 8 '15 at 14:50
  • Please see my update.
    – Tuan
    Jun 8 '15 at 15:36
  • 1
    -1 .bash_profile is not temporary.
    – Maythux
    Jun 8 '15 at 15:59
  • @Maythux You are correct. I first overlooked it, then forgot to edit ))
    – Pilot6
    Jun 8 '15 at 20:03

Maythux 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 

Also works in .bash_profile to source $HOME/.bashrc

  • A word of warning: when you start sourcing these numerous rc/profile files from one another madness ensues. Do the research and get things in the correct files. You'll be glad you did later. Nothing worse than finding your path containing the same routes multiple times.
    – RichieHH
    Sep 8 '18 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.