How to set JAVA environment variables in Linux or CentOS
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
# 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/
How to set JAVA environment variables in Linux or CentOS的更多相关文章
- Java environment variables and their functionality
Explanations of Functionalities: 1. PATH env variable It is used to search the command directory whe ...
- Linux environment variables (环境变量)
Environment variables are often used to store a list of paths of where to search for executables, li ...
- CVE: 2014-6271、CVE: 2014-7169 Bash Specially-crafted Environment Variables Code Injection Vulnerability Analysis
目录 . 漏洞的起因 . 漏洞原理分析 . 漏洞的影响范围 . 漏洞的利用场景 . 漏洞的POC.测试方法 . 漏洞的修复Patch情况 . 如何避免此类漏洞继续出现 1. 漏洞的起因 为了理解这个漏 ...
- Debian Environment Variables
原文:EnvironmentVariables General Environment variables are named strings available to all application ...
- How to install JDK (Java Development Kit) on Linux
This tutorial will guide you on how to install JDK (Java Development Kit) on Linux. Since I use Cent ...
- Java学习笔记之Linux下的Java安装和配置
0x00 概述 由于使用 yum 或者 apt-get 命令 安装 openjdk 可能存在类库不全,从而导致用户在安装后运行相关工具时可能报错的问题,所以此处我们推荐采用手动解压安装的方式来安装 J ...
- Java Environment Setting
As a non-Java developer, I am quit stuck in Java environment setting because I am not familiar with ...
- Java学习心得之 Linux下搭建Java环境
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Java学习心得之 Linux下搭建Java环境 1.前言2.JDK安装3.配置环境变量4. ...
- Java学习心得之 Linux下搭建JavaWeb环境
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Java学习心得之 Linux下搭建JavaWeb环境 1. 前言2. Java安装3. t ...
随机推荐
- WebClient.DownloadData突然失灵
有如下的代码: try { byte[] acsMetadata; using (WebClient webClient = new WebClient()) { acsMetadata = we ...
- 计算两端yuv视频流中每一帧的ssim值
方法同上一篇,仅仅不多这里在计算的时候用了opencv1的接口,出现了一些问题.最后总算攻克了. 程序: #include <stdlib.h> #include <stdio.h& ...
- iOS8开发~Swift(二)Playground
一.Playground介绍 Playground是Xcode6中自带的Swift代码开发环境.俗话说"功欲善其事,必先利其器".曾经在Xcode5中编写脚本代码.比如编写JS.其 ...
- wireshark 的使用(filter的用法)
转自:http://blog.csdn.net/hanyuxinting/article/details/5558095 过滤器语法---------------------------------- ...
- js的正则匹配 和 blur
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js&qu ...
- Office WORD如何关闭自动检查语法
只要把打钩的地方全部去掉即可.
- STL - 容器 - Map(二)
把Map用作关联式数组 MapAdvanceTest.cpp #include <map> #include <string> #include <iostream> ...
- 常用工具软件之串口终端工具——SecureCRT和xshell
SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简单的说是Windows下登录UNIX或Linux服务器主机的软件.SecureCRT支持SSH,同时支持Telnet和rlog ...
- 恭喜您成为2014年度Microsoft MVP!
- eclipse JRE(unbound)问题
eclipse eclipse eclipse eclipse eclipse JRE(unbound) createTime--2016年10月18日14:18:59 Author:Mary ...