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 ...
随机推荐
- 为什么要使用href=”javascript:void(0);”?
JavaScript中语句最后的分号是可以缺省的,那为何要使用javascript:;而不是javascript:呢? 是习惯还是规范,我疑惑了! 具有代码洁癖的coder们,没事多写一个分号,圣洁的 ...
- C#.NET常见问题(FAQ)-如何把资源嵌入到项目中
首先把图像的资源添加到项目中, 选择资源文件(常规),修改一下这个资源的名字(比如叫做ButtonPic) 我们假定已经把图像放到了项目的某个文件夹下(比如Pic文件夹下,注意不是bin目录下 ...
- Python标记去重
预逻辑脚本代码: uniqueList = [] def isDuplicate(inValue): if inValue in uniqueList: return 1 else: uniqueLi ...
- tail 命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/11/07/2758084.html ail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可 ...
- #define中的“#”和“##”的作用
在#define中,标准只定义了#和##两种操作: #用来把参数转换成字符串: ##则用来连接两个前后两个参数,把它们变成一个字符串.
- Phpcms之L()函数
.phpcms\languages\zh-cn 中文语言包2.phpcms\languages\en 英文语言包 phpcms v9语言包建立 在phpcms v9二次开发之模型类的应用 ...
- sql distinct 不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符
有个文章的表内容是列项,类型是text 我查询的是内容相同的文章,把其中的一个删除 select 内容 from 文章 group by 内容 having count(*)>1 查询ID和题目 ...
- 使用轻量级JAVA 爬虫Gecco工具抓取新闻DEMO
写在前面 最近看到Gecoo爬虫工具,感觉比较简单好用,所有写个DEMO测试一下,抓取网站 http://zj.zjol.com.cn/home.html,主要抓取新闻的标题和发布时间做为抓取测试对象 ...
- mysqladmin: connect to server at 'localhost' failed
1:mysqladmin: connect to server at 'localhost' failed 2: 3: 4:
- webpack插件html-webpack-plugin
1.插件安装 npm install html-webpack-plugin --save-dev 2.插件使用 webpack.config.js配置文件为: var htmlWebpackPlug ...