I decided that I wanted to develop a Java application. Why Java? I already have a little experience in Java developing a couple Android applications, and figured why let what little I know go to waste. Why Adopt? I hopped on IRC (yes, it is most definitely still around >freenode #java) and discussed Java with a few more experienced than myself. The consensus there was to install Adopt over Oracle or the standard OpenJDK that is in the Ubuntu/Mint repositories. Adopt has Long Term Support is FOSS (Free Open Source Software), and Oracle is commercial, not FOSS. Why am I posting this? Because the instructions for installing Adopt in Linux Mint are a mess for the average person, especially those new to Linux/Ubuntu/Mint and Java.
I’m no expert in either of these topics, Linux, or Java. If you have any suggestions, please let me know!
Which Version Do We install?
This post is written in January of 2020. Things may have changed by the time you read this, so we need to prepare for the fact that it may. First off, we need to decide which version of Adopt that you want to install. The original instructions are here, https://adoptopenjdk.net/installation.html. Visit the site and check the current versions that are offered. In general, you probably want the latest LTS version (Long Term Support).
At the time of this writing, the latest LTS version was 11. You also have to decide if you want the HotSpot, or OpenJ9 version. More than likely, you will want the HotSpot version. If you want to read up on the differences a little more, I found this article here.
Which ever version you decide to install, make a note of it, you will need this information later.
What os am i running?
This may seem like a stupid question, but trust me, it’s not. You may know that you are running Ubuntu, or Mint, but we will need a little more information. First off, if you really don’t know the version number you are currently running, which is easy to forget after awhile, open a terminal and type the following:
andrew@andrew-satellite:~$ lsb_release -a No LSB modules are available. Distributor ID: LinuxMint Description: Linux Mint 19.3 Tricia Release: 19.3 Codename: tricia
For Ubuntu, this will list the version and code name of the operating system (OS). If you are using Mint, it will list the Mint code name info, but not the Ubuntu version that it is based off of, and this is what we need. So, for Mint, type the following into a terminal, and make a note of where it says UBUNTU_CODENAME.
andrew@andrew-satellite:~$ cat /etc/os-release NAME="Linux Mint" VERSION="19.3 (Tricia)" ID=linuxmint ID_LIKE=ubuntu PRETTY_NAME="Linux Mint 19.3" VERSION_ID="19.3" HOME_URL="https://www.linuxmint.com/" SUPPORT_URL="https://forums.ubuntu.com/" BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/" PRIVACY_POLICY_URL="https://www.linuxmint.com/" VERSION_CODENAME=tricia UBUNTU_CODENAME=bionic
So, for my system above, the Ubuntu code name is Bionic. This is important, so make a note!
Install the repository
We could just install the JDK and be done with it, but what if we want to update it? Then we have to reinstall it manually over and over again. No, what we want to do is install it through a repository, that way it gets updated regularly.
If you don’t have a terminal open, do so now. It shouldn’t matter what directory you’re in, but just for safetly, type:
This will ensure that we are in your home directory.
Now, copy and paste the following code into your terminal, unless you really want to type it out…
wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
The command above downloads the public key to the AdoptOpenJDK repository and installs it on your machine.
Now the part that caused me the most headache. The instructions on the AdoptOpenJDK installation instruction page didn’t work for installing it on Mint. The step that actually puts the repo on your system is broken. I couldn’t figure it out, but I did figure out a work around by just creating an entry for it in my sources.list.d. In a terminal (press enter after each line):
cd /etc/apt/sources.list.d sudo gedit adoptopenjdk.list
GEdit will open a blank text file. We are creating this so your system knows where to look for the the AdoptOpenJDK software. In the blank text file, put the following:
deb [arch=amd64] https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ bionic main
Depending on your system, you may need to tweak the line above a little bit, particularly if your system is a different architecture such as 32 bit, arm, or something else. Copy the web address for the repository above and paste it in your web browser. You will first be presented with two folders, click dists, and then click on the folder that corresponds with your OS codename (Bionic in my case), then click on the folder Main. Now you will see folders with different architectures listed. Go ahead and click on yours, on a PC it will probably be the binary-amd64 folder. You will see a file named Packages, we need some information in this file! Click on it and go ahead and save it somewhere on your computer. After we get the information we need from it you can delete it (it’s only like 88k). Once it downloads open it up. From Firefox, you can just click on your downloads button on the navigation bar and click on the file to open it.
At the top of the Packages file, on the first line you should see something like this:
Copy or make a note of the package name. We need this soon. If you don’t have a terminal open, do so now. We need to update our repositories and apply any updates to our system before we install Adopt. From a terminal:
sudo apt update && sudo apt dist-upgrade
Once your system has finished updating, install AdoptOpenJDK by typing “sudo apt install packageName where packageName is the name of the package you made a note of from the Packages file. For instance, on my system:
sudo apt install adoptopenjdk-11-hotspot
After installation is complete, verify that the install worked by typing “java -version” and “javac -version” in a terminal. Something like this:
andrew@andrew-satellite:~$ java -version openjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode) andrew@andrew-satellite:~$ javac -version javac 11.0.6 andrew@andrew-satellite:~$
Setup environment variables
We are almost done! Lastly, we need to setup our environment variables. This is one other area where my ignorance of Linux shows. I wasn’t sure where I was supposed to put these. I know you can place these in your ~/.bashrc file, but then it wouldn’t be available to other users on your system. This may or may not be an issue for you. Just to be safe, I placed my environment variables in /etc/profile. To do this, let’s backup our existing profile file first. In a terminal:
sudo cp /etc/profile /etc/profile.bak sudo gedit /etc/profile
Now, let’s add our environment variables to profile. Once the file opens, go all the way to the bottom of the file, and add the following two lines:
export JAVA_HOME=/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64 export PATH=$JAVA_HOME/bin:$PATH
If your Adopt version is different, you will obviously have to edit the directory for JAVA_HOME a little bit. If you aren’t sure, just go to the jvm directory and see what directory is there:
andrew@andrew-satellite:~$ cd /usr/lib/jvm andrew@andrew-satellite:/usr/lib/jvm$ ls -la total 16 drwxrwxr-x 3 root root 4096 Jan 25 20:45 . drwxr-xr-x 143 root root 4096 Jan 25 20:45 .. drwxrwxr-x 10 root root 4096 Jan 25 20:45 adoptopenjdk-11-hotspot-amd64 -rw-rw-r-- 1 root root 2270 Jan 16 01:42 .adoptopenjdk-11-hotspot-amd64.jinfo andrew@andrew-satellite:/usr/lib/jvm$
So, in my case, it’s adoptopenjdk-11-hotspot-amd64.
At this point, all we need to do is log out/in or reboot your system so the environment variables will be loaded into memory. Congratulations, you now have AdoptOpenJDK installed! Next, we need to install an IDE (Integrated Development Environment). I’ll eventually follow up this post with another one detailing how to install IntelliJ and getting it setup with the lombok plugin, which I was also introduced to in the IRC chat.