How to Set JAVA_HOME / PATH variables Under Linux Bash Profile
2014-05-14 10:48
579 查看
原文转载至:http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/
~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to
set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.
Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
Set PATH as follows:
Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file. Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately:
OR
Verify new settings:
Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
Please note that the file
~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.
/etc/bash.bashrc file for all users:
Next setup PATH / JAVA_PATH variables as follows:
Save and close the file. Once again you need to type the following command to activate the path settings immediately:
OR
~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to
set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.
Set JAVA_HOME / PATH for a single user
Login to your account and open .bash_profile file$ vi ~/.bash_profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java
Set PATH as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
Feel free to replace /usr/java/jdk1.5.0_07 as per your setup. Save and close the file. Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately:
$ source ~/.bash_profile
OR
$ . ~/.bash_profile
Verify new settings:
$ echo $JAVA_HOME $ echo $PATH
Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java
Please note that the file
~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.
Set JAVA_HOME / PATH for all user
You need to setup global config in /etc/profile OR/etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
Save and close the file. Once again you need to type the following command to activate the path settings immediately:
# source /etc/profile
OR
# . /etc/profile
相关文章推荐
- How to Set JAVA_HOME / PATH variables Under Linux Bash Profile
- How to Set Classpath for Java on Windows and Linux
- How to set JAVA environment variables in Linux or CentOS
- How to set the JAVA_HOME variable in Mac OS X – Snow Leopard
- Web Service ERROR: Set JAVA_HOME to the path where the JDK (6.0 or higher) is installed解决方式
- [linux]How to set PATH in shell script, and keep it avaiable even after it exits
- How to Set and Unset Local, User and System Wide Environment Variables in Linux
- How to fix the issue that GEM_HOME and/or GEM_PATH not set issue for rvm in mac version 10.12
- How to Set up Cplex Dev Environment under Linux
- How to Set $JAVA_HOME environment variable on Mac OS X
- How do I setup JAVA_HOME and Path variables in Windows?
- How to set JAVA_HOME on mac
- How to change Mysql root password under linux ?
- 如何设置Java桌面程序界面外观(How to Set the Look and Feel)
- How To Clone A Database Home From One Server To Other(same SID,directory,path)
- rcp(插件开发)How to add a folder to java build path as library
- How to get a notification from Linux when the set of network interfaces changes
- Linux: 3 methods to set environment variables
- How to Profile Memory in Linux
- How to set up a BitTorrent tracker on Linux