2

My environment variables are correct? What is the correct way to use them in Ubuntu? I put them at the end of .bashrc file or edit the end of /etc/environment to able to use the $JAVA_HOME and $M2_HOME configuration and on my user?

$JAVA_HOME

JAVA_HOME="/usr/lib/jvm/java-8-oracle/​"
CLASSPATH="JAVA_HOME/lib/:$CLASSPATH"
PATH="$JAVA_HOME/bin/:$PATH"

$M2_HOME

M2_HOME="/usr/share/maven/"
M2="$M2_HOME/bin"
PATH="$M2:$PATH" PATH=$M2:$PATH

1 Answers1

1

In bash you can set variables like this:

export JAVA_HOME=/usr/lib/jvm/java-8-oracle/​

export CLASSPATH=JAVA_HOME/lib/:$CLASSPATH
export PATH=$JAVA_HOME/bin/:$PATH
export M2_HOME=/usr/share/maven/
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

for more info on environment variables you can read https://help.ubuntu.com/community/EnvironmentVariables

Prashant Chikhalkar
  • 2,411
  • 2
  • 18
  • 25
  • the export when I restart the computer lose the settings – ricardoramos Aug 06 '15 at 20:25
  • refer the link in answer and read the point Persistent environment variables – Prashant Chikhalkar Aug 06 '15 at 20:28
  • From what I understand Variable expansion is a form of Persistent environment variables, but does not work in /etc/environment. – ricardoramos Aug 06 '15 at 20:36
  • I think that the way will be putting them at the end of .bashrc file – ricardoramos Aug 06 '15 at 20:37
  • You can add it to the file .profile or .bashrc or your current shell profile file (located in your home directory). Then, each time you open your shell it will be loaded. This will help you http://unix.stackexchange.com/questions/117467/how-to-permanently-set-environmental-variables – Prashant Chikhalkar Aug 06 '15 at 20:38
  • I do not remember what was the command to load the current settings without restarting the computer, Prashant Chikhalkar you let me know? – ricardoramos Aug 06 '15 at 20:41
  • load current settings? I'm not getting you .. Are you able to set env var succesfully? – Prashant Chikhalkar Aug 06 '15 at 20:48
  • Hello Prashant Chikhalkar, insert the environment variables at the end of .bashrc file as your suggestion and did the tutorial: http://javarevisited.blogspot.in/2012/08/how-to-get-environment-variables-in.html, but only shows the PATH variable and does not show the Java home. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" – ricardoramos Aug 10 '15 at 19:03
  • It seems that everything is working because when I type in the terminal the command: $ echo $JAVA_HOME show /usr/lib/jvm/java-8-oracle/​ and $ echo $M2_HOME show /usr/share/maven/. Because my Java code does not display the environment variables $ JAVA_HOME and $ M2_HOME? Java Code: http://javarevisited.blogspot.in/2012/08/how-to-get-environment-variables-in.html – ricardoramos Aug 10 '15 at 19:13