Linux Java
Oracle Java 8 JDK - Java Development Kit - apt-get install method
Add repository, this will also display how to install different version of Oracle Java
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update
Oracle packages become available now
sudo apt-get install oracle-java8-installer
Oracle Java 7 JDK - zip file install
This will treat how to install Oracle Java in Ubuntu. This method does not use any package management software. Use a link in the references section for other options.
Download the 32-bit or 64-bit Linux from "http://www.oracle.com/technetwork/java/javase/downloads/index.html" "compressed binary file" - it has a ".tar.gz" file extension.
Uncompress it
tar -xvf jdk-7u80-linux-x64.tar.gz (32-bit) tar -xvf jdk-7u80-linux-x64.tar.gz (64-bit)
The JDK 7 package is extracted into ./jdk1.7.0_80 directory.
Now move the JDK 7 directory to /usr/lib
sudo mkdir -p /usr/lib/jvm sudo mv ./jdk1.7.0_80 /usr/lib/jvm/
Optional: Environment variables
$ sudo vi /etc/environment #add environment variables system wise, all users PATH="search/paths:/usr/lib/jvm/jdk-oracle/bin" JAVA_HOME=/usr/lib/jvm/jdk-oracle
Log log out and log back in, you should have Java available to you now.
Now run
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_80/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_80/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_80/bin/javaws" 1
This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.
Correct the file ownership and the permissions of the executables:
sudo chmod a+x /usr/bin/java sudo chmod a+x /usr/bin/javac sudo chmod a+x /usr/bin/javaws sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_80
Run
sudo update-alternatives --config java
You will see output similar to the one below - choose the number of jdk1.7.0_80 - for example 3 in this list (unless you have have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):
$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-6-oracle1/bin/java 1047 auto mode 1 /usr/bin/gij-4.6 1046 manual mode 2 /usr/lib/jvm/java-6-oracle1/bin/java 1047 manual mode 3 /usr/lib/jvm/jdk1.7.0_80/bin/java 1 manual mode
Press enter to keep the current choice [*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk1.7.0_80/bin/java to provide /usr/bin/java (java) in manual mode
Repeat the above for:
sudo update-alternatives --config javac sudo update-alternatives --config javaws
Verify
$ java -version java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
Install another alternative manually
Before
Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/golang-go 10 auto mode 1 /usr/bin/gccgo-go 5 manual mode 2 /usr/bin/golang-go 10 manual mode
Installed manually unzipped GoLang into /usr/local/go but was not added to alternatives. Use command below to add it on:
sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 2
After
Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/golang-go 10 auto mode 1 /usr/bin/gccgo-go 5 manual mode 2 /usr/bin/golang-go 10 manual mode 3 /usr/local/go/bin/go 2 manual mode
Then run command to change go binary available in your shell
sudo update-alternatives --config go #then select 3
When you run
$ go version #the version of go will be the one from /usr/local/go location.
References
- Java Ubuntu official wiki