• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting PATH in Ubuntu

 
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm new to linux and using Ubuntu 11.10.
I set up M2_HOME variable for Maven and added it to path as follows:-


I tested it by writing mvn --version which showed me correct version details.
But as soon as I exit the current terminal and open up a new one and write mvn --version, it says ' the program 'mvn' is currently not installed..... '.
How to make the M2_HOME and PATH setting permanent.

Please advise.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

you must set and export your variables in one of the startup files that bash executes during login:
/etc/profile - for all users
or one of the following file in the user home directory
~/.bash_profile
~/.bash_login
~/.profile

check bash documentation for details: webpage
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I was following these instructions :

The ~/.bash_profile ($HOME/.bash_profile) or ~/.prfile file is executed when you login using console or remotely using ssh. Type the following command to edit ~/.bash_profile file, enter:
$ vi ~/.bash_proflle

Append the $PATH settings, enter:
export PATH=${PATH}:${HOME}/bin

Save and close the file.



I entered the first command vi~/.bash_profile on the terminal and pressed ENTER.
The terminal now shows a blank screen with ~ at the beginning of every line & ~/.bash_profile [New File] at the bottom.
Now if i try to write anything then nothing appears in the terminal while the bottom line shows 'Nothing to register'.

Is there a way to open such file in Notepad and then append the line ?

Please advise.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

use gedit - this is a gui editor similar to notepad in WIndows.
Run gedit in the terminal, if it is not installed, fire this command to install it from online repositories
and enter a password of the root user:


First check which of these startup files exists in your home patch.
Note that bash executes commands only from the first file that exists, and ignore the rest.
Suppose, for example, that your environment settings is currently stored in the .profile, but .bash_rc does not exist,
then after you will create the .bash_rc, bash during login will execute .bash_rc and will ignore your current settings from the .profile file.
Therefore it is better to modify the existing environment file than creating a new one.
To check which file actually exist in your home patch fire this command:


Then fire the editor, modify the file and save it.

After these changes, logout and login to the system and you will see that your new variables will be permanent.

 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ireneusz,

The third line


~$ cd ~
~$ ls .pro* .bash*
.bash_history .bash_logout .profile



is different for me. It has .bash_profile.swj and other entries as well. I decided to modify .profile file.
This is my .profile file.


And this is the output on my terminal :


I have two issues :
1. Few entries viz. maven & tomcat are repeated here. My PATH was already showing me maven entry , so how to remove the repeated entry here.
2. If I write echo $M2_HOME$ or echo $CATALINA_HOME$ on Terminal, it doesn't show anything, so how to create other environment variables permanently here.

Thanks a lot for your response.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) To get rid of the duplicate entries in the PATH, find all of the locations where you added to the PATH, and remove one of them. If you remove the PATH setting from ~/.profile, what PATH do you get?

2) Try using "export M2_HOME=..." instead of just "M2_HOME=...". Ditto for CATALINA_HOME.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

Could you please tell me where I should look/how to find all of the locations where PATH is added. I'm completely new to Ubuntu and have no idea about it's file structure. Also in WIndows, we have just one place to add/edit any variable, why are there so many places in linux ?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pramod talekar wrote:
1. Few entries viz. maven & tomcat are repeated here. My PATH was already showing me maven entry , so how to remove the repeated entry here.


Your .profile file calls .bashrc - probably .bashrc (or maybe /etc/profile) contains entries for maven and tomcat too.
Just delete this line "PATH=${PATH}:${CATALINA_HOME}/bin" from your .profile,
for maven you must check the other files and remove one of the duplicate command.

pramod talekar wrote:
2. If I write echo $M2_HOME$ or echo $CATALINA_HOME$ on Terminal, it doesn't show anything, so how to create other environment variables permanently here.


Use export command - export makes variable available to child processes. Without export variables are only seen in the current shell process, not in subprocesess.
export M2_HOME=/home/pramod/software/apache-maven-3.0.3
export CATALINA_HOME=/home/pramod/apache-tomcat-7.0.23

and not echo $name$ - this is a WIndows syntax ( echo %name% )
just echo $name or echo ${name}
You can also check environment variables by env | grep your-variable-name, like this
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ireneusz,

Thank you so much for your help.

But I should I get back to Windows as I'm really finding it difficult to manage my system now.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ireneusz,

I found out that apart from .profile file, I had made the same entry of tomcat and maven to PATH in /etc/environment file.
But now as I try to delete those entries to bring in some uniformity , I get the message , "You don't have the permissions necessary to save the file.Please check that you typed the location correctly and try again."

Please advise.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you are editing the file while logged in as a user who has only read access to the file. You can do one of two things:

a) Throw away the changes, and rerun gedit using "sudo gedit" and change the file again. Then you should be able to save it.

b) Save the file to another location, such as your desktop. Then use "sudo cp" to copy the file back to where it belongs. But before copying the file, check its permissions and owners - you will need to make certain that after you copy the file that it still has the same permissions ans owners (you will probably have to reapply both the permissions and owners).
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

Thank you so much.
I followed the first option.

Thanks a lot.
Ubuntu/Linux doesn't seem very difficult now..
 
Hold that thought. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic