DEV Community

SMJ
SMJ

Posted on

Ubuntu 18.04 install Java and Eclipse IDE

Requirements

  1. Download an JDK gz file.
    https://www.oracle.com/technetwork/java/javase/downloads/index.html

  2. Download Eclipse IDE installer gz file.
    https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2018-12/R/eclipse-inst-linux64.tar.gz
    you can select an mirror site for downloading it.

Config JDK

Extract and Install Java

tar -xvf ~/Downloads/jdk1.8.0_201.tar.gz

Create an folder to store it.

sudo mkdir /usr/lib/jvm/jdk1.8.0_201

Move extracted package to the directory.

sudo mv jdk1.8.0_201*/* /usr/lib/jvm/jdk1.8.0_201/

Run the commands below to configure java.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_201//bin/java" 1010 
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_201//bin/javac" 1010 
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0_201//bin/javaws" 1010
Enter fullscreen mode Exit fullscreen mode

Create Java Environment Variables.

New an file.
sudo vim /etc/profile.d/javajdk.sh

Copy this lines to javajdk.sh

export J2SDKDIR=/usr/lib/jvm/jdk1.8.0_201
export J2REDIR=/usr/lib/jvm/jdk1.8.0_201/jre
export PATH=$PATH:/usr/lib/jvm/jdk1.8.0_201/bin:/usr/lib/jvm/jdk1.8.0_201/db/bin:/usr/lib/jvm/jdk1.8.0_201/jre/bin
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_201
export DERBY_HOME=/usr/lib/jvm/jdk1.8.0_201/db
Enter fullscreen mode Exit fullscreen mode

Make it effective.
source /etc/profile.d/javajdk.sh

Test if successful.
Run the commandjava -version, it will show messages like this

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
Enter fullscreen mode Exit fullscreen mode

if it, Congratulations!

Install Eclipse

Extract eclipse installer gz file, then just run the eclipse-inst executable file.
or run the command on eclipse installer directiry
./eclipse-inst.

Next, it is some easy steps!

Add an icon on application lancher

Step1: change current directiry to /usr/share/applicaitons

cd /usr/share/applicaitons

Step2: new a Java.desktop file.

Input the lines:

[Desktop Entry]
Encoding=UTF-8
Name=Java #name it
Comment=Eclipse-Java
Exec=/path/eclipse #your path
Icon=/path/icon.xpm #your path
Terminal=false
StartupNotify=true
Type=Application
Categories=Application;Development;
Enter fullscreen mode Exit fullscreen mode

Step3: Give it execution permission.

Run the command:
sudo chmod +x Java.desktop

Reference

https://websiteforstudents.com/install-oracle-java-jre-jdk-on-ubuntu-18-04-lts-beta/

This is my first post, if there are any errors, please correct me:)

Top comments (0)