[donotprint]
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | None |
Time | 5m |
CentOS Linux JAVA package names
- java-1.7.0-openjdk – OpenJDK Runtime Environment
- java-1.7.0-openjdk-devel – OpenJDK Development Environment
To see a list of all available JDK on the system type the following command:
# yum search java | grep -i --color JDK
Sample outputs:
Install Java SDK on a CentOS Linux
Open the Terminal and type the following yum command to install OpenJDK as root user:
# yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
Sample outputs:
Loaded plugins: downloadonly, fastestmirror, security Loading mirror speeds from cached hostfile * base: mirror.wiredtree.com * epel: mirror.steadfast.net * extras: bay.uchicago.edu * updates: mirror.team-cymru.org Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.51-2.4.4.1.el6_5 will be installed --> Processing Dependency: jpackage-utils >= 1.7.3-1jpp.2 for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: tzdata-java for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: rhino for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libpulse.so.0(PULSE_0)(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libasound.so.2(ALSA_0.9.0rc4)(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libasound.so.2(ALSA_0.9)(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libpulse.so.0()(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libgif.so.4()(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libasound.so.2()(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Processing Dependency: libXtst.so.6()(64bit) for package: 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 --> Running transaction check ---> Package alsa-lib.x86_64 0:1.0.22-3.el6 will be installed ---> Package giflib.x86_64 0:4.1.6-3.1.el6 will be installed --> Processing Dependency: libSM.so.6()(64bit) for package: giflib-4.1.6-3.1.el6.x86_64 --> Processing Dependency: libICE.so.6()(64bit) for package: giflib-4.1.6-3.1.el6.x86_64 ---> Package jpackage-utils.noarch 0:1.7.5-3.12.el6 will be installed ---> Package libXtst.x86_64 0:1.2.1-2.el6 will be installed ---> Package pulseaudio-libs.x86_64 0:0.9.21-14.el6_3 will be installed --> Processing Dependency: libsndfile.so.1(libsndfile.so.1.0)(64bit) for package: pulseaudio-libs-0.9.21-14.el6_3.x86_64 --> Processing Dependency: libsndfile.so.1()(64bit) for package: pulseaudio-libs-0.9.21-14.el6_3.x86_64 --> Processing Dependency: libasyncns.so.0()(64bit) for package: pulseaudio-libs-0.9.21-14.el6_3.x86_64 ---> Package rhino.noarch 0:1.7-0.7.r2.2.el6 will be installed --> Processing Dependency: jline for package: rhino-1.7-0.7.r2.2.el6.noarch ---> Package tzdata-java.noarch 0:2013i-2.el6 will be installed ---> Package xorg-x11-fonts-Type1.noarch 0:7.2-9.1.el6 will be installed --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.2-9.1.el6.noarch --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.2-9.1.el6.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.2-9.1.el6.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.2-9.1.el6.noarch --> Running transaction check ---> Package jline.noarch 0:0.9.94-0.8.el6 will be installed ---> Package libICE.x86_64 0:1.0.6-1.el6 will be installed ---> Package libSM.x86_64 0:1.2.1-2.el6 will be installed ---> Package libasyncns.x86_64 0:0.8-1.1.el6 will be installed ---> Package libsndfile.x86_64 0:1.0.20-5.el6 will be installed --> Processing Dependency: libvorbisenc.so.2()(64bit) for package: libsndfile-1.0.20-5.el6.x86_64 --> Processing Dependency: libvorbis.so.0()(64bit) for package: libsndfile-1.0.20-5.el6.x86_64 --> Processing Dependency: libogg.so.0()(64bit) for package: libsndfile-1.0.20-5.el6.x86_64 --> Processing Dependency: libFLAC.so.8()(64bit) for package: libsndfile-1.0.20-5.el6.x86_64 ---> Package ttmkfdir.x86_64 0:3.0.9-32.1.el6 will be installed ---> Package xorg-x11-font-utils.x86_64 1:7.2-11.el6 will be installed --> Processing Dependency: libfontenc.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.2-11.el6.x86_64 --> Processing Dependency: libXfont.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.2-11.el6.x86_64 --> Running transaction check ---> Package flac.x86_64 0:1.2.1-6.1.el6 will be installed ---> Package libXfont.x86_64 0:1.4.5-3.el6_5 will be installed ---> Package libfontenc.x86_64 0:1.0.5-2.el6 will be installed ---> Package libogg.x86_64 2:1.1.4-2.1.el6 will be installed ---> Package libvorbis.x86_64 1:1.2.3-4.el6_2.1 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================== Package Arch Version Repository Size ================================================================================================== Installing: java-1.7.0-openjdk x86_64 1:1.7.0.51-2.4.4.1.el6_5 updates 26 M Installing for dependencies: alsa-lib x86_64 1.0.22-3.el6 base 370 k flac x86_64 1.2.1-6.1.el6 base 243 k giflib x86_64 4.1.6-3.1.el6 base 37 k jline noarch 0.9.94-0.8.el6 base 86 k jpackage-utils noarch 1.7.5-3.12.el6 base 59 k libICE x86_64 1.0.6-1.el6 base 53 k libSM x86_64 1.2.1-2.el6 base 37 k libXfont x86_64 1.4.5-3.el6_5 updates 136 k libXtst x86_64 1.2.1-2.el6 base 29 k libasyncns x86_64 0.8-1.1.el6 base 24 k libfontenc x86_64 1.0.5-2.el6 base 24 k libogg x86_64 2:1.1.4-2.1.el6 base 21 k libsndfile x86_64 1.0.20-5.el6 base 233 k libvorbis x86_64 1:1.2.3-4.el6_2.1 base 168 k pulseaudio-libs x86_64 0.9.21-14.el6_3 base 462 k rhino noarch 1.7-0.7.r2.2.el6 base 778 k ttmkfdir x86_64 3.0.9-32.1.el6 base 43 k tzdata-java noarch 2013i-2.el6 updates 147 k xorg-x11-font-utils x86_64 1:7.2-11.el6 base 75 k xorg-x11-fonts-Type1 noarch 7.2-9.1.el6 base 520 k Transaction Summary ================================================================================================== Install 21 Package(s) Total download size: 29 M Installed size: 100 M Is this ok [y/N]: y Downloading Packages: (1/21): alsa-lib-1.0.22-3.el6.x86_64.rpm | 370 kB 00:00 (2/21): flac-1.2.1-6.1.el6.x86_64.rpm | 243 kB 00:00 (3/21): giflib-4.1.6-3.1.el6.x86_64.rpm | 37 kB 00:00 (4/21): java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64.rpm | 26 MB 00:02 (5/21): jline-0.9.94-0.8.el6.noarch.rpm | 86 kB 00:00 (6/21): jpackage-utils-1.7.5-3.12.el6.noarch.rpm | 59 kB 00:00 (7/21): libICE-1.0.6-1.el6.x86_64.rpm | 53 kB 00:00 (8/21): libSM-1.2.1-2.el6.x86_64.rpm | 37 kB 00:00 (9/21): libXfont-1.4.5-3.el6_5.x86_64.rpm | 136 kB 00:00 (10/21): libXtst-1.2.1-2.el6.x86_64.rpm | 29 kB 00:00 (11/21): libasyncns-0.8-1.1.el6.x86_64.rpm | 24 kB 00:00 (12/21): libfontenc-1.0.5-2.el6.x86_64.rpm | 24 kB 00:00 (13/21): libogg-1.1.4-2.1.el6.x86_64.rpm | 21 kB 00:00 (14/21): libsndfile-1.0.20-5.el6.x86_64.rpm | 233 kB 00:00 (15/21): libvorbis-1.2.3-4.el6_2.1.x86_64.rpm | 168 kB 00:00 (16/21): pulseaudio-libs-0.9.21-14.el6_3.x86_64.rpm | 462 kB 00:00 (17/21): rhino-1.7-0.7.r2.2.el6.noarch.rpm | 778 kB 00:00 (18/21): ttmkfdir-3.0.9-32.1.el6.x86_64.rpm | 43 kB 00:00 (19/21): tzdata-java-2013i-2.el6.noarch.rpm | 147 kB 00:00 (20/21): xorg-x11-font-utils-7.2-11.el6.x86_64.rpm | 75 kB 00:00 (21/21): xorg-x11-fonts-Type1-7.2-9.1.el6.noarch.rpm | 520 kB 00:00 -------------------------------------------------------------------------------------------------- Total 7.2 MB/s | 29 MB 00:04 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : libICE-1.0.6-1.el6.x86_64 1/21 Installing : 2:libogg-1.1.4-2.1.el6.x86_64 2/21 Installing : libSM-1.2.1-2.el6.x86_64 3/21 Installing : libXtst-1.2.1-2.el6.x86_64 4/21 Installing : jpackage-utils-1.7.5-3.12.el6.noarch 5/21 Installing : alsa-lib-1.0.22-3.el6.x86_64 6/21 Installing : libfontenc-1.0.5-2.el6.x86_64 7/21 Installing : libXfont-1.4.5-3.el6_5.x86_64 8/21 Installing : 1:xorg-x11-font-utils-7.2-11.el6.x86_64 9/21 Installing : giflib-4.1.6-3.1.el6.x86_64 10/21 Installing : flac-1.2.1-6.1.el6.x86_64 11/21 Installing : 1:libvorbis-1.2.3-4.el6_2.1.x86_64 12/21 Installing : libsndfile-1.0.20-5.el6.x86_64 13/21 Installing : libasyncns-0.8-1.1.el6.x86_64 14/21 Installing : pulseaudio-libs-0.9.21-14.el6_3.x86_64 15/21 Installing : jline-0.9.94-0.8.el6.noarch 16/21 Installing : rhino-1.7-0.7.r2.2.el6.noarch 17/21 Installing : tzdata-java-2013i-2.el6.noarch 18/21 Installing : ttmkfdir-3.0.9-32.1.el6.x86_64 19/21 Installing : xorg-x11-fonts-Type1-7.2-9.1.el6.noarch 20/21 Installing : 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 21/21 Verifying : pulseaudio-libs-0.9.21-14.el6_3.x86_64 1/21 Verifying : ttmkfdir-3.0.9-32.1.el6.x86_64 2/21 Verifying : tzdata-java-2013i-2.el6.noarch 3/21 Verifying : libXfont-1.4.5-3.el6_5.x86_64 4/21 Verifying : libfontenc-1.0.5-2.el6.x86_64 5/21 Verifying : flac-1.2.1-6.1.el6.x86_64 6/21 Verifying : jline-0.9.94-0.8.el6.noarch 7/21 Verifying : alsa-lib-1.0.22-3.el6.x86_64 8/21 Verifying : 2:libogg-1.1.4-2.1.el6.x86_64 9/21 Verifying : 1:libvorbis-1.2.3-4.el6_2.1.x86_64 10/21 Verifying : 1:xorg-x11-font-utils-7.2-11.el6.x86_64 11/21 Verifying : xorg-x11-fonts-Type1-7.2-9.1.el6.noarch 12/21 Verifying : libSM-1.2.1-2.el6.x86_64 13/21 Verifying : libICE-1.0.6-1.el6.x86_64 14/21 Verifying : 1:java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.x86_64 15/21 Verifying : rhino-1.7-0.7.r2.2.el6.noarch 16/21 Verifying : libasyncns-0.8-1.1.el6.x86_64 17/21 Verifying : giflib-4.1.6-3.1.el6.x86_64 18/21 Verifying : libsndfile-1.0.20-5.el6.x86_64 19/21 Verifying : jpackage-utils-1.7.5-3.12.el6.noarch 20/21 Verifying : libXtst-1.2.1-2.el6.x86_64 21/21 Installed: java-1.7.0-openjdk.x86_64 1:1.7.0.51-2.4.4.1.el6_5 Dependency Installed: alsa-lib.x86_64 0:1.0.22-3.el6 flac.x86_64 0:1.2.1-6.1.el6 giflib.x86_64 0:4.1.6-3.1.el6 jline.noarch 0:0.9.94-0.8.el6 jpackage-utils.noarch 0:1.7.5-3.12.el6 libICE.x86_64 0:1.0.6-1.el6 libSM.x86_64 0:1.2.1-2.el6 libXfont.x86_64 0:1.4.5-3.el6_5 libXtst.x86_64 0:1.2.1-2.el6 libasyncns.x86_64 0:0.8-1.1.el6 libfontenc.x86_64 0:1.0.5-2.el6 libogg.x86_64 2:1.1.4-2.1.el6 libsndfile.x86_64 0:1.0.20-5.el6 libvorbis.x86_64 1:1.2.3-4.el6_2.1 pulseaudio-libs.x86_64 0:0.9.21-14.el6_3 rhino.noarch 0:1.7-0.7.r2.2.el6 ttmkfdir.x86_64 0:3.0.9-32.1.el6 tzdata-java.noarch 0:2013i-2.el6 xorg-x11-font-utils.x86_64 1:7.2-11.el6 xorg-x11-fonts-Type1.noarch 0:7.2-9.1.el6 Complete!
Set the JAVA_HOME environment variable on a CentOS Linux
RHEL and CentOS Linux install OpenJDK into /usr/lib/jvm/ directory:
# ls -l /usr/lib/jvm/
Sample outputs:
total 4
drwxr-xr-x. 3 root root 4096 Feb 24 17:00 java-1.7.0-openjdk-1.7.0.51.x86_64
lrwxrwxrwx. 1 root root 21 Feb 24 17:00 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Feb 24 17:00 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx. 1 root root 38 Feb 24 17:00 jre-1.7.0-openjdk.x86_64 -> java-1.7.0-openjdk-1.7.0.51.x86_64/jre
lrwxrwxrwx. 1 root root 29 Feb 24 17:00 jre-openjdk -> /etc/alternatives/jre_openjdk
Set the JAVA_HOME to the directory containing a bin/java executable using export command:
# export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
Open the shell configuration file such as $HOME/.bashrc and at the bottom of the file, type the following line:
export JAVA_HOME="/usr/lib/jvm/jre-1.7.0-openjdk.x86_64"
Save and close the file. See “How to Set JAVA_HOME / PATH variables Under Linux Bash Profile” tutorial for more information.
Test your Java installation
Create a program called HelloWorld.java as follows:
$ cat > HelloWorld.java
Sample code:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World! This is a test code by nixCraft!"); } }
Save and close the file. Compile and run it as follows:
$ javac HelloWorld.java
$ java HelloWorld
Sample outputs:
Hello, World! This is a test code by nixCraft!
How do I run a .Jar java file based app?
The syntax is:
$ java -jar file.jar
$ java -jar /path/to/my/java/app.jar
$ java -jar /path/to/my/java/app.jar arg1 arg2
See also
- Ubuntu Linux Install Sun Java Development Kit ( JDK ) and Java Runtime Environment ( JRE )
- Ubuntu Linux: Install Latest Oracle Java 7
- Debian Linux Install Eclipse Java / C / C++ IDE with JDK
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 10 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
I can’t seem to get around some dependencies that I cannot find.
–> Processing Dependency: python-xml for package: javapackages-tools-2.0.1-25.1.x86_64
–> Processing Dependency: libxslt-tools for package: javapackages-tools-2.0.1-25.1.x86_64
–> Finished Dependency Resolution
Error: Package: javapackages-tools-2.0.1-25.1.x86_64 (Education)
Requires: python-xml
Error: Package: javapackages-tools-2.0.1-25.1.x86_64 (Education)
Requires: libxslt-tools
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
Any advice?
Can you state your version of CentOS Linux system? This tutorial only tested on Centos 6.x (may work on centos 5.x too).
Thanks for your help. I am using Centos 6.5. I’ve pasted the complete output here: http://pastebin.com/9Vvi9AKF
Thanks a lot for this discription ;) but u must in the end see of installation the version of ur java by using #java -version that command line must put out in terminal something like this : Java TM et Java Hotspot
u can get that by using # alternatives –config java
Thanks a lot. It helps me installing the jdk on my CentOS.
once again thanks.
Thank you very much! Very useful guide!
Thanks for the Guide. I tried so many ways to install java. But this one only make useful.
while executing $HOME/.bashrc as a root I am getting error like
bash: /root/.bashrc: Permission denied
Please help how to overcome this
Oct 13, 2016 10:45:49 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor gslenvosys.xml
Oct 13, 2016 10:45:52 AM org.apache.tomcat.util.modeler.Registry registerComponent
SEVERE: Null component Catalina:type=JspMonitor,name=jsp,WebModule=//localhost/gslenvosys,J2EEApplication=none,J2EEServer=none
Oct 13, 2016 10:45:52 AM org.apache.catalina.startup.HostConfig deployDescriptor
SEVERE: Error deploying configuration descriptor gslenvosys.xml
java.lang.NoSuchMethodError: org.apache.naming.NamingContextEnumeration.(Ljava/util/Iterator;)V
at org.apache.naming.resources.FileDirContext.list(FileDirContext.java:306)
at org.apache.naming.resources.ProxyDirContext.list(ProxyDirContext.java:487)
at org.apache.catalina.startup.TldConfig.tldScanResourcePathsWebInf(TldConfig.java:515)
at org.apache.catalina.startup.TldConfig.tldScanResourcePaths(TldConfig.java:484)
at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:257)
at org.apache.catalina.startup.TldConfig.lifecycleEvent(TldConfig.java:634)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4377)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1345)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
at java.lang.Thread.run(Thread.java:745)
While starting Tomcat i got the below error of loadng Context file.
Please help