Installing JDK on Linux: Two Different Approaches
Installing JDK on Linux: Two Different Approaches
Environment with Internet Access
Using YUM to Install
- Search for Java-related packages
- 1
yum -y list java*
Alternatively,
- 1
yum search jdk
- Install the JDK package
- 1
yum install java-1.8.0-openjdk.x86_64
- Verify the installation
- 1
java -version
- The default installation path with YUM is:
/usr/lib/jvm - Configure JAVA_HOME in the system profile
- 1
vi /etc/profile
Append the following lines at the end of the file:
- 1
- 2
- 3
- 4
- 5
# Set Java environment variables
JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
Apply the changes to the profile:
source /etc/profile (Ensure there is a space after 'source')
Environment Without Internet Access
Manual Installation via Download and Upload
- Visit the Oracle website to download the appropriate JDK version for Linux. For this example, we use
jdk-8u261-linux-x64.tar.gz, although your downloaded file might vary in version number, as long as it ends with.tar.gz. - Create a directory for Java installation
Create a new folder under /usr/local/:
- 1
- 2
mkdir /usr/local/java
cd /usr/local/java
Place the downloaded file jdk-8u261-linux-x64.tar.gz into the /usr/local/java/ directory.
- Extract the JDK archive
- 1
tar -zxvf jdk-8u261-linux-x64.tar.gz
- Configure Environment Variables
Edit the profile file:
vi /etc/profile
Add the following configuration:
- 1
- 2
- 3
- 4
- 5
- 6
# Set Java environment variables
JAVA_HOME=/usr/local/java/jdk1.8.0_261
JRE_HOME=/usr/local/java/jdk1.8.0_261/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
Ensure that JAVA_HOME and JRE_HOME match your actual installlation paths and JDK version.
Reload the configuration:
- 1
source /etc/profile
- Validate Installation
- 1
java -version
If the command returns the version information, then the JDK has been successfully installed.
Installing Apache Maven
-
Go to the official Maven website and download the
.tar.gzpackage. Upload it to your server. -
Extract the archive:
tar -zxvf apache-maven-3.8.2-bin.tar.gz -
Update the profile to include Maven's bin directory.
-
Modify the local repository loctaion. All Maven artifacts are stored here (
/usr/local/apache-maven-3.6.3/ck). Navigate to theconfdirectory and editsettings.xml:Locate
<localRepository>and add the following line:<localRepository>/usr/local/apache-maven-3.6.3/ck</localRepository>Find the
<mirrors>section and add Alibaba's mirror configuration. -
Save the changes and exit the editor.
-
Reload the updated profile:
source /etc/profile -
Test Maven installation:
mvn -v
This should display the Maven version if everything is configured correct.