How To Install Java on CentOS and Fedora
Introduction
This tutorial will show you how to install Java on CentOS 7 (also 5, 6, 6.5), Fedora 20, and RHEL. Java is a popular software platform that allows you to run Java applications and applets.
The installation of the following versions of Java are covered:
- OpenJDK 7
- OpenJDK 6
- Oracle Java 8
- Oracle Java 7
Feel free to skip to your desired section using the Contents button on the sidebar!
Prerequisites
Before you begin this guide, you should have a regular, non-root user with sudo
privileges configured on both of your servers--this is the user that you should log in to your servers as. You can learn how to configure a regular user account by following steps 1-4 in our initial server setup guide for Ubuntu 14.04.
Variations of Java
There are three different editions of the Java Platform: Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). This tutorial is focused on Java SE (Java Platform, Standard Edition).
There are two different Java SE packages that can be installed: the Java Runtime Environment (JRE) and the Java Development Kit (JDK). JRE is an implementation of the Java Virtual Machine (JVM), which allows you to run compiled Java applications and applets. JDK includes JRE and other software that is required for writing, developing, and compiling Java applications and applets.
There are also two different implementations of Java: OpenJDK and Oracle Java. Both implementations are based largely on the same code but OpenJDK, the reference implementation of Java, is fully open source while Oracle Java contains some proprietary code. Most Java applications will work fine with either but you should use whichever implementation your software calls for.
You may install various versions and releases of Java on a single system, but most people only need one installation. With that in mind, try to only install the version of Java that you need to run or develop your application(s).
Install OpenJDK 7
This section will show you how to install the prebuilt OpenJDK 7 JRE and JDK packages using the yum package manager, which is similar to apt-get for Ubuntu/Debian. OpenJDK 7 is the latest version of OpenJDK.
Install OpenJDK 7 JRE
To install OpenJDK 7 JRE using yum, run this command:
sudo yum install java-1.7.0-openjdk
At the confirmation prompt, enter y
then RETURN
to continue with the installation.
Congratulations! You have installed OpenJDK 7 JRE.
Install OpenJDK 7 JDK
To install OpenJDK 7 JDK using yum, run this command:
sudo yum install java-1.7.0-openjdk-devel
At the confirmation prompt, enter y
then RETURN
to continue with the installation.
Congratulations! You have installed OpenJDK 7 JDK.
Install OpenJDK 6
This section will show you how to install the prebuilt OpenJDK 6 JRE and JDK packages using the yum package manager.
Install OpenJDK 6
To install OpenJDK 6 JRE using yum, run this command:
sudo yum install java-1.6.0-openjdk
At the confirmation prompt, enter y
then RETURN
to continue with the installation.
Congratulations! You have installed OpenJDK 6 JRE.
Install OpenJDK 6 JDK
To install OpenJDK 6 JDK using yum, run this command:
sudo yum install java-1.6.0-openjdk-devel
At the confirmation prompt, enter y
then RETURN
to continue with the installation.
Congratulations! You have installed OpenJDK 6 JDK.
Install Oracle Java 8
This section of the guide will show you how to install Oracle Java 8 update 60 JRE and JDK (64-bit), the latest release of these packages at the time of this writing.
Note: You must accept the Oracle Binary Code License Agreement for Java SE, which is one of the included steps, before installing Oracle Java.
Install Oracle Java 8 JRE
Note: If you would like to install a different release of Oracle Java 8 JRE, go to the Oracle Java 8 JRE Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm
package. Substitute the copied download link in place of the highlighted part of the wget
command.
Change to your home directory and download the Oracle Java 8 JRE RPM with these commands:
cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jre-8u60-linux-x64.rpm"
Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):
sudo yum localinstall jre-8u60-linux-x64.rpm
Now Java should be installed at /usr/java/jdk1.8.0_60/jre/bin/java
, and linked from /usr/bin/java
.
You may delete the archive file that you downloaded earlier:
rm ~/jre-8u60-linux-x64.rpm
Congratulations! You have installed Oracle Java 8 JRE.
Install Oracle Java 8 JDK
Note: If you would like to install a different release of Oracle Java 8 JDK, go to the Oracle Java 8 JDK Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm
package. Substitute the copied download link in place of the highlighted part of the wget
command.
Change to your home directory and download the Oracle Java 8 JDK RPM with these commands:
cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.rpm"
Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):
sudo yum localinstall jdk-8u60-linux-x64.rpm
Now Java should be installed at /usr/java/jdk1.8.0_60/jre/bin/java
, and linked from /usr/bin/java
.
You may delete the archive file that you downloaded earlier:
rm ~/jdk-8u60-linux-x64.rpm
Congratulations! You have installed Oracle Java 8 JDK.
Install Oracle Java 7
This section of the guide will show you how to install Oracle Java 7 update 79 JRE and JDK (64-bit).
Note: You must accept the Oracle Binary Code License Agreement for Java SE, which is one of the included steps, before installing Oracle Java.
Install Oracle Java 7 JRE
Note: If you would like to install a different release of Oracle Java 7 JRE, go to the Oracle Java 7 JRE Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm
package. Substitute the copied download link in place of the highlighted part of the wget
command.
Change to your home directory and download the Oracle Java 7 JRE RPM with these commands:
cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jre-7u79-linux-x64.rpm"
Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):
sudo yum localinstall jre-7u79-linux-x64.rpm
Now Java should be installed at /usr/java/jdk1.7.0_79/jre/bin/java
, and linked from /usr/bin/java
.
You may delete the archive file that you downloaded earlier:
rm ~/jre-7u79-linux-x64.rpm
Congratulations! You have installed Oracle Java 7 JRE.
Install Oracle Java 7 JDK
Note: If you would like to install a different release of Oracle Java 7 JDK, go to the Oracle Java 7 JDK Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm
package. Substitute the copied download link in place of the highlighted part of the wget
command.
Change to your home directory and download the Oracle Java 7 JDK RPM with these commands:
cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm"
Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):
sudo yum localinstall jdk-7u79-linux-x64.rpm
Now Java should be installed at /usr/java/jdk1.7.0_79/jre/bin/java
, and linked from /usr/bin/java
.
You may delete the archive file that you downloaded earlier:
rm ~/jdk-7u79-linux-x64.rpm
Congratulations! You have installed Oracle Java 7 JDK.
Set Default Java
If you installed multiple versions of Java, you may want to set one as your default (i.e. the one that will run when a user runs the java
command). Additionally, some applications require certain environment variables to be set to locate which installation of Java to use. This section will show you how to do this.
By the way, to check the version of your default Java, run this command:
java -version
Using Alternatives
The alternatives
command, which manages default commands through symbolic links, can be used to select the default Java command.
To print the programs that provide the java
command that are managed by alternatives
, use this command:
sudo alternatives --config java
Here is an example of the output:
There are 5 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/java/jdk1.8.0_60/jre/bin/java
2 /usr/java/jdk1.7.0_79/jre/bin/java
Enter to keep the current selection[+], or type selection number:
Simply enter the a selection number to choose which java
executable should be used by default.
Using Environment Variables
Many Java applications use the JAVA_HOME
or JRE_HOME
environment variables to determine which java
executable to use.
For example, if you installed Java to /usr/java/jdk1.8.0_60/jre/bin
(i.e. java
executable is located at /usr/java/jdk1.8.0_60/jre/bin/java
), you could set your JAVA_HOME
environment variable in a bash shell or script like so:
export JAVA_HOME=/usr/java/jdk1.8.0_60/jre
If you want JAVA_HOME
to be set for every user on the system by default, add the previous line to the /etc/environment
file. An easy way to append it to the file is to run this command:
sudo sh -c "echo export JAVA_HOME=/usr/java/jdk1.8.0_60/jre >> /etc/environment"
Conclusion
Congratulations, you are now set to run and/or develop your Java applications!
转载自:https://www.digitalocean.com/community/tutorials/how-to-install-java-on-centos-and-fedora
How To Install Java on CentOS and Fedora的更多相关文章
- Steps to Install Hadoop on CentOS/RHEL 6---reference
http://tecadmin.net/steps-to-install-hadoop-on-centosrhel-6/# The Apache Hadoop software library is ...
- Install SVN (Subversion) Server on Fedora 20/19, CentOS/Red Hat (RHEL) 6.5/5.10
Install SVN (Subversion) Server on Fedora 20/19, CentOS/Red Hat (RHEL) 6.5/5.10 Updated by JR on Mar ...
- Google Chrome 55 Released – Install on RHEL/CentOS 7/6 and Fedora 25-20
Google Chrome is a freeware web browser developed by Google Inc. Google Chrome team proudly announce ...
- Install MySQL 5.7 on Fedora 25/24, CentOS/RHEL 7.3/6.8/5.11
MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user ...
- How to Install JAVA 8 (JDK/JRE 8u111) on Debian 8 & 7 via PPA
Oracle JAVA 8 Stable release has been released on Mar,18 2014 and available to download and install. ...
- 如何在CentOS 7 / Fedora 31/30/29上安装ELK Stack
原文地址:https://computingforgeeks.com/how-to-install-elk-stack-on-centos-fedora/ 原作者: Josphat Mutai 译者: ...
- 如何在CentOS/RHEL & Fedora上安装MongoDB 3.2
MongoDB(名称取自"huMONGOus")是一个有着全面灵活的索引支持和丰富的查询的数据库.MongoDB通过GridFS提供强大的媒体存储.点击这里获取MongoDB的更多 ...
- How to install Jenkins on CentOS 7
How to install Jenkins on CentOS 7 on March 3, 2018 by AmirLeave a comment Introduction Jenkins is a ...
- How to install cacti on centos 6
Cacti – Network and performance monitoring tool Cacti is one of best monitoring tool used to monit ...
随机推荐
- spark 简介
spark 是基于内存计算的 大数据分布式计算框架,spark基于内存计算,提高了在大数据环境下处理的实时性,同时保证了高容错性和高可伸缩性,允许用户将spark部署在大量廉价的硬件上,形成集群. 1 ...
- IE8文件下载启用
在IE8的浏览器中,需要进行一些设置 Internet选项→安全→本地Intranet→自定义级别→下载→文件下载→启用 禁用迅雷下载:工具栏和扩展→迅雷下载支持→右键禁用
- java环境变量的设置
java安装好后需要配置一下环境变量,配置方法如下: 1.在系统变量里添加两条记录: 1)变量名:JAVA_HOME,变量值为java安装路径,如:C:\Program Files\Java\jdk1 ...
- iOS,视图相关
1.移除视图的所以子视图 2.自定义视图(UIView) 3.处理悬浮窗口(类似微信视频),等比缩放 4.自定义前面视图(可以手写字) 5.图片拉伸的几种方式,计算文本占用空间大小 6.UILable ...
- lua下的简单OO实现
笔者学习了当前(文末各文献)lua下的各种OO实现方法.略作笔记. 也提出了一些自己的想法.主要还是记录供将来着之参考. 1.概述 首先[2]PIL第二版中给出了OO的基于table的实现方式 ...
- GPS部标平台的架构设计(四)-百度地图设计
部标GPS软件平台之百度地图设计 地图是客户端中不可缺少的一个模块,很多人在设计和画图时候,喜欢加上地图引擎这样高大上的字眼,显得自己的平台有内涵,说白了就是用第三方的SDK来开发,早期的GPS监 控 ...
- PostgreSQL function examples
warehouse_db=# CREATE TABLE warehouse_tbl(warehouse_id INTEGER NOT NULL,warehouse_name TEXT NOT NULL ...
- C语言堆和栈
堆和栈的区别 一个由C/C++编译的程序占用的内存分为以下几个部分1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈.2.堆区(heap ...
- 2.2 C#的注释
注释,是代码中的一些“说明文档”,注释注释本身不会参与程序代码的编译和运行,仅仅是为了方便程序员阅读. C#的注释分为:单行注释.多行注释.文档注释. 单行注释的符号是2条斜杠线(斜线的方向是左下到右 ...
- swift基础:第六部分:类与对象
http://reactnative.cn/docs/0.24/getting-started.html#content(react Native 开发文档) 互联网这个时代,你松懈一天,就会有很多很 ...