How to set JAVA environment variables in Linux or CentOS
2016-01-09 19:54
633 查看
How to set JAVA environment variables JAVA_HOME and PATH in Linux
After installing new java (jdk or jre) or latest Java you may have usually find that the version of java is not exactly the same which you have installed. It might be showing you the same old version.
How to check the java version which is currently set in linux system ?
Answer: Run the below given command
Now we will install new Java and set the java variables
Download the rpm file from Oracle website. Click here (If you have installed with tar ball then again there is no problem)
I installed the jdk-1.7.0_21-fcs.i586 hence showing practical case to case (You can skip the step if you installed through tar ball)
Install JDK (java) rpm
Generally after installation Java file goes to the path /usr/java/jdk-xx-version/. In my case it is in
/usr/java/jdk1.7.0_21
To check where is the latest Java (JDK or JRE) you have installed in your system. Run below given command
Step1 : Open /root/.bash_profile through your text editor. (I prefer to use vi editor)
And paste the given below two lines
Step 2 : Now enable the Java variable without system restart (On system restart it bydefault set the java variable)
Step 3: Now check the Java version,JAVA_HOME and PATH variables.It should show you correct information as you have set.
Given below is the reference of my system’s root bash_profile file
[root@localhost ~]# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export JAVA_HOME=/usr/java/jdk1.7.0_21 export PATH=/usr/java/jdk1.7.0_21/bin:$PATH
[root@localhost ~]#
(2) $HOME/.bashrc = To set environment for login user.
(3) $HOME/.bash_profile = To set environment for login user
Note: .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
(4) Create a shell script inside /etc/profile.d/ with .sh extension. and make the file executable.
(5) Create a shell script in some other location and give its path in /etc/rc.local
Referred : http://sharadchhetri.com/2013/06/03/how-to-set-java-environment-variables-in-linux-or-centos/
After installing new java (jdk or jre) or latest Java you may have usually find that the version of java is not exactly the same which you have installed. It might be showing you the same old version.
How to check the java version which is currently set in linux system ?
Answer: Run the below given command
# java --version or # java -version
Now we will install new Java and set the java variables
Download the rpm file from Oracle website. Click here (If you have installed with tar ball then again there is no problem)
I installed the jdk-1.7.0_21-fcs.i586 hence showing practical case to case (You can skip the step if you installed through tar ball)
Install JDK (java) rpm
rpm -ivh jdk-1.7.0_21-fcs.i586
Generally after installation Java file goes to the path /usr/java/jdk-xx-version/. In my case it is in
/usr/java/jdk1.7.0_21
To check where is the latest Java (JDK or JRE) you have installed in your system. Run below given command
find / -name java
How to set Java variable environment
Follow the given below steps (Replace the version no. as per your new Java version installed in your system)Step1 : Open /root/.bash_profile through your text editor. (I prefer to use vi editor)
And paste the given below two lines
export JAVA_HOME=/usr/java/jdk1.7.0_21 export PATH=/usr/java/jdk1.7.0_21/bin:$PATH
Step 2 : Now enable the Java variable without system restart (On system restart it bydefault set the java variable)
source /root/.bash_profile
Step 3: Now check the Java version,JAVA_HOME and PATH variables.It should show you correct information as you have set.
java --version echo $JAVA_HOME echo $PATH
Given below is the reference of my system’s root bash_profile file
[root@localhost ~]# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export JAVA_HOME=/usr/java/jdk1.7.0_21 export PATH=/usr/java/jdk1.7.0_21/bin:$PATH
[root@localhost ~]#
Other files and location where you can set Java variable and what are the difference
(1) /etc/profile = To set environment variable to all users(2) $HOME/.bashrc = To set environment for login user.
(3) $HOME/.bash_profile = To set environment for login user
Note: .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
(4) Create a shell script inside /etc/profile.d/ with .sh extension. and make the file executable.
(5) Create a shell script in some other location and give its path in /etc/rc.local
Referred : http://sharadchhetri.com/2013/06/03/how-to-set-java-environment-variables-in-linux-or-centos/
相关文章推荐
- linux AIO (异步IO) 那点事儿
- linux下异步RPC的阶段性总结-非阻塞SOCKET客户端
- Linux下socket异步通讯聊天程序
- linux c socket之异步IO
- Linux下openoffice+swftools安装教程
- Linux错误代码含义/Linux return Error Code
- Linux printk and log level
- linux设备驱动makefile入门解析
- 2016年关于 Linux 发展趋势的八大预测
- Linux Core dump
- Linux学习之查看是否安装软件
- su sudo gksudo-转
- Linux调试 call trace dump_stuck
- linux中终端复用工具screen的介绍
- 搭建linux上的Eclipse+PHP编程环境
- linux定时执行任务
- CentOS 7 静态IP配置
- aliyun Centos7安装vsftpd服务
- CentOS RM安装
- Linux开机启动过程分析