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 ...
随机推荐
- windows server 2012 IE增强的安全配置如何关闭
http://jingyan.baidu.com/article/6181c3e076ac0b152ff15354.html 打开左下角的 服务端 关闭这个就可以了
- js生成pdf报表
由于前台html已经动态生成报表,而且,前台有一个功能,一个date range组件,当你拖动的时候,报表会在不提交到后台的情况下动态变化.因此需要用到js生成生报表: 用到的组件: jquery.j ...
- iOS日期加减
- (NSDate *)jsDateFromBeginDate:(NSDate *)beginDate todays:(int)days { NSDate *dateTemp = [[NSDate a ...
- java中的数据加密
记录 一.java中的数据加密 Java提供的安全模型和API 加密基础知识 使用JAVA实现加密 二.Java提供的安全模型和API 2.1.Java语言本身的安全性 自动内存管理:对于生成的对象在 ...
- 高阶函数 实现sum(2)(3) 柯里化
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- jgGrid获得的id值是主键的id而不是jqGrid的行号值
{name:'cityId',index:'cityId',sorttype:'int',width:0,hidden:true,key:true}, 一定要将你的主键值的的key设置为true,这样 ...
- SpringMVC之ModelAndView的用法(转)
原文地址:https://blog.csdn.net/qq30211478/article/details/78016155 (一)使用ModelAndView类用来存储处理完后的结果数据,以及显示该 ...
- VC++程序员如何做好界面
本屌丝在新春放假期间闲来无事,在各大编程论坛溜达了一圈.发现年前的帖子中,有VC++程序员在界面开发方面遇到了很多苦恼,有抱怨界面工作不好做的,有抱怨用错了界面库的,也有紧急求得技术问题帮助的.看到这 ...
- Spring MVC request flow
1. When we enter a URL in the browser, the request comes to the dispatcher servlet.The dispatcher se ...
- Java中创建实例化对象的几种方式
Java中创建实例化对象有哪些方式? ①最常见的创建对象方法,使用new语句创建一个对象.②通过工厂方法返回对象,例:String s =String.valueOf().(工厂方法涉及到框架)③动用 ...