This article is a 'how-to' for installing Oracle's Java JDK 8 (or SE 8) and Google's Android Studio on Linux Mint 17.1 (Rebecca). If you wish to develop software on the Android platform on your Mint 17.1 PC, then this 'how-to' is for you. Note that most necessary steps are performed at the command line in a terminal - if you are not familiar with this, I suggest reading about it first before trying out this 'how-to'.
On a newly-installed and updated Linux Mint 17.1, only OpenJDK JRE (Java Runtime Environment) 7 is installed by default. This can be verified by executing the following in a terminal:
java -version
The output is as follows:
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
Although whether the JRE or JDK version of OpenJDK 7 is installed by default is not clearly indicated in the output, it can be easily verified by executing the following:
update-alternatives --list java
The output is as follows:
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
This clearly indicate that only the JRE is installed by default. Google's Android Studio requires the full Java JDK, and the recommended version is Oracle's Java (JDK or SE 7 and above). So, you can either delete the OpenJDK 7 JRE and install Oracle's Java JDK 8 in it's place, or install Oracle's Java JDK 8 and keep the OpenJDK 7 JRE. Either way you have to tell Linux Mint which Java is the default by using the 'update-alternatives' command. This 'how-to' implements the second option - install Oracle's Java JDK 8 and keep the OpenJDK 7 JRE.
Point your web browser to the Oracle SE download page here and download the latest version of the 32-bit or 64-bit JDK (not Server JRE or the JRE) - currently at version 8u31 (or 1.8.0_31). It is also recommended that you download the API docs and demos (+samples) for the JDK - although this is not required for Android development on Android Studio. Once the packages have been downloaded, execute the following commands:
cd Downloads
tar xzvf jdk-8u31-linux-x64.tar.gz
tar xzvf jdk-8u31-linux-x64-demos.tar.gz
unzip jdk-8u31-docs-all.zip -d jdk1.8.0_31
The last 2 commands in the above is only applicable if you have downloaded the demos and the documentation. The 2nd command above will create a 'jdk1.8.0_31' directory in the Downloads directory while the last 2 commands above (if applicable) will create the 'sample', 'demo' and 'docs' directories under the 'jdk1.8.0_31' directory.
Now execute the following commands:
sudo mv jdk1.8.0_31/ /usr/lib/jvm/
cd ~
This will move the whole jdk1.8.0_31 directory to the /usr/lib/jvm directory - where the root of the current OpenJDK 7 JRE resides. If you are curious (like me), you can do a 'ls -la /usr/lib/jvm' command to find out what resides in this directory. Don't be surprised to find both the OpenJDK 6 and OpenJDK 7 directories listed there - why I don't know. Notice also that there is also a 'default-java' link which currently points to java-1.7.0-openjdk-amd64. This link is actually set by the 'default-jre' and the 'default-jre-headless' package which are installed by default. To remove this link, execute the following command in a terminal:
sudo apt-get remove default-jre default-jre-headless
Notice that the owner and group of the jdk1.8.0_31 directory is still in your name and group. You can keep it as it is if you are the only user of the PC or you can set this to root by executing:
sudo chown -R root:root /usr/lib/jvm/jdk1.8.0_31
The next thing to do is to tell Linux Mint where Oracle Java JDK resides. For this we use the 'update-alternatives' command. Execute the following commands one by one from the terminal (note that all commands are on a single line):
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_31/bin/java" 1500 --slave "/usr/share/man/man1/java.1" "java.1" "/usr/lib/jvm/jdk1.8.0_31/man/man1/java.1"
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_31/bin/javac" 1500 --slave "/usr/share/man/man1/javac.1" "javac.1" "/usr/lib/jvm/jdk1.8.0_31/man/man1/javac.1"
These will install all the necessary links to Oracle's Java. Note that the 2nd command is strictly not essential to Android program development - it only sets up the link for the Java compiler.
Next we have to tell Linux Mint the default Java to use. Just remember that Open JDK 7 Java is the default Java for a newly installed Linux Mint 17 system - however, since we installed the above links with a priority of 1500 (higher than OpenJDK's 1075), the default Java was automatically set to Oracle's Java.
To verify that all have been set correctly, you can use the following commands:
update-alternatives --display java
update-alternatives --display javac
If the output to the two queries above contains the following lines:
link currently points to /usr/lib/jvm/jdk1.8.0_31/bin/java
link currently points to /usr/lib/jvm/jdk1.8.0_31/bin/javac
then everything have been set correctly. Just another quick check can be performed by executing the following command:
java -version
If the output for the command is:
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
then Oracle JDK 8 has been set up properly.
Now that Linux Mint has been informed about Oracle's Java, you still have to perform one last task before Java is set up and ready for use. This is to set the environment variables and paths correctly for the whole system. Execute the following command:
sudo nano /etc/profile
This will execute the nano text editor and open the /etc/profile file for editing. Now add the following lines at the end of the file.
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_31
export PATH=$PATH:$JAVA_HOME/bin
Save the file and close it. Note that, upon system startup, these will set the JAVA_HOME and PATH environment variables for the whole system. The JAVA_HOME environment variable points to the JDK root while the PATH environment variable will add the /bin directory of the JDK to whatever path that has already been specified. This will enable the 'javac' command to be executed from any directory.
Now log out and then log in again to the Linux Mint system in order to make sure that both the environment variables are set. Check by opening a terminal and executing one by one:
echo $JAVA_HOME
echo $PATH
You can then delete the tar.gz and zip files which were downloaded from the web in order to free up disk space.
Now that you have installed Oracle JDK 8 on your system, it's time to download and install Google's Android Studio. Point your browser to here and click on the big green button and then on android-studio for Linux package (NOT the SDK tools only). Wait for the download to finish and then start a terminal and execute the following command:
unzip Downloads/android-studio-ide-135.1641136-linux.zip
This will decompress the contents of the zip file downloaded into a new directory called 'android-studio'. To start Android Studio setup, execute the following commands, one by one:
cd android-studio/bin
./studio.sh
A window similar to the one shown below will appear asking whether you would like to import any settings. If this is the first time you are using Android Studio, it will be likely that you don't have anything to import. However, if you are moving from an older version of Android Studio, you may want to keep any settings made previously - in this case specify the location of the settings and let the setup wizard do the job.
Click on the OK button to proceed. Android Studio will begin loading as shown in the figure below.
After a while, the Setup Wizard screen similar to the one shown below, will appear. Click on the Next button to continue.
The next screen similar to the one shown below will appear.
The Standard type of setup is already selected - this is recommended unless you want to customize the setup. Click on the Next button and the the next screen will appear.
If you are using Linux Mint 17.1 and you have Virtualization Technology (vt-d) enabled in your PC BIOS and Linux kernel, then it will be detected as shown on the wizard's screen. You can read up more on this technology at the URL shown on the screen - just remember that the web page there is for Windows only - to read more on Linux and Virtualization Technology, click here. Then click on the Next button.
The next screen that appears as shown below is where you agree to accept the license for installing Google's Android SDK. Note that this is a must and cannot be skipped if you want to develop software for the Android platform. Click on Accept and the the Finish button.
The SDK components will begin downloading as shown in the screen below.
Once downloading and installation is completed, a log window will appear as shown. Click on the Finish button.
The next screen shown is the Android Studio IDE itself (shown below). You have now successfully installed Android Studio on your Linux Mint 17.1 PC.
Notice the 'Check for updates now.' on the IDE window - click on Check and if there are any updates, a window similar to the one shown below will pop up.
Click on the Update and Restart button. Android Studio will close and the updates will begin downloading as shown.
Once the updates have been installed, Android Studio will start again.
Congratulations! You have successfully installed Oracle's Java and Google's Android Studio on your Linux Mint 17.1 PC. Remember that, at the moment, you have to start a terminal, change to the correct bin directory and then launch studio.sh in order to start Android Studio. Surely there must be an easier way and there is! To place a launcher icon on your desktop, follow the steps outlined below:
- Right-click on an empty portion of your desktop and select 'Create a new launcher here...'
- A window similar to the one shown below, will appear. You an now enter a name for the item - 'Android Studio' seems appropriate here. Then for the command, click on the Browse button and select the 'studio.sh' file in your home directory. In the comment field, enter any text you like - 'Google's Programming IDE for Android' seems appropriate here. Leave the 'Launch in Terminal?' field unchecked.
- For the icon, click on the rocket icon, and navigate to your home directory, double-click on android-studio and bin directories and then select the idea.png file. Then click OK, followed by another OK.
A window may pop up asking you whether you want to create a menu item for Android Studio also. Should you say 'Yes', that item will be placed in the 'Other' category but will not be visible until you log off and log in again. You can test the launcher by double-clicking on it.
Where to go from here? You must realize that Android Studio is relatively new (Google was using Eclipse IDE previously) so the number of good tutorials on the web is limited. However, a quick search on Google revealed some good sites - I recommend that you visit some of the sites and see whether they meet your needs.
Happy computing!
EDIT: This blog was edited to use the latest Java from Oracle - Java SE update 31. In addition, the 'update-alternatives' command were changed to use 1500 as the 'priority' option, in order to set the system to use Oracle's Java automatically. Because of this change, the 'update-alternatives --set' commands were removed. Also, it was found that it was unnecessary to remove the links to the OpenJDK 7 Java - the 'update-alternatives' command will take care of which Java to use by default.
Some of the 'update-alternatives --list' commands were replaced by the 'update-alternatives --display' commands as these were more appropriate in these situations.
Strictly speaking, it is not necessary to set the PATH environment variable to include the Java bin directory in order to execute the 'javac' command, but I leave this to user to decide. No harm will come to the system if you do this. The rest of the blog remains unchanged.
Take note that there are more Oracle Java commands that can be set by using 'update-alternatives', but the minimum required by Android Studio is given in this blog. For those who wants to set up a Oracle Java programming environment, read my blog here.
After reading my previous article on installing Oracle Java on Ubuntu 14.04, one of my college asked me how to remove OpenJDK 7 from his Ubuntu system. After helping him out, I realize that the process may be useful to people in the same situation. For example, if you do get a warning from Android Studio similar to the one shown below, then it's time to remove OpenJDK 7 and install Oracle's JDK 8 in its place. For instruction on how to install Oracle's JDK 8, see my blog here.
First, check for all Java installed (just in case) by executing the following command in a terminal.
sudo update-alternatives --config java
If you see a response such as the one shown below, then there is only one Java installed.
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Nothing to configure.
As a safety check, execute the following also:
sudo update-alternatives --config javac
Again, if you see something similar to the one shown below, then there is also one java compiler installed.
There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
Nothing to configure.
To list out all the Java packages already installed, execute the following command:
sudo dpkg --list | grep -i jdk
The listing will show all the OpenJDK packages that you need to remove. To list our all the JRE packages, execute the following command:
sudo dpkg --list | grep -i jre
To actually remove all the installed OpenJDK packages, you can either use a terminal and execute the proper commands, or, if you have Synaptic installed on your system, use it to remove the installed packages. Of these 2 methods, using Synaptic will be described first.
Launch Synaptic and then type 'openjdk' in the Quick filter text box. A screen similar to the one below (the screen has been expanded for clarity) will appear. Click on each of the green box to the left of each item you want removed and select 'Mark for Complete Removal'. Should you get an additional window pop-up asking you to mark additional packages, click on the 'Mark' button. When everything is done, click on the 'Apply' button. Another window will pop up - click on the 'Apply' button and the removal process will begin. Close Synaptic when done.
To remove OpenJDK using the command line in a terminal, open a terminal and execute:
sudo apt-get purge openjdk*
Enter your password if prompted, and then press the Enter key to accept the the default of 'Yes'. The OpenJDK packages will all be purged from the system. You can dos a quick check by using the commands:
sudo dpkg --list | grep -i jdk
sudo dpkg --list | grep -i jre
These 2 commands will return nothing, indicating that all OpenJDK related packages has been removed.
That's it - to download and install Oracle JDK 8, follow the instructions in my previous blog.
This article will guide you on how to install Google's Android Studio and set it up properly. For those of of you wondering what is the Android Studio, it is simply the IDE (Integrated Development Environment) for the Android platform. Basically it contains all the necessary tools for developing Android software, for example, an IDE and the Android SDK tools, etc. It replaces the Eclipse-based ADT formerly used by Google.
IMPORTANT NOTE FOR 64-BIT USERS: If you are using the 64-bit version of Ubuntu 14.04 LTS, it is important to note that Android Studio requires the 32-bit libraries to run properly. Although this requirement is not clearly stated under 'System Requirements', the clue is obtained from the message 'Tested on Ubuntu® 12.04, Precise Pangolin (64-bit distribution capable of running
32-bit applications'. The standard installation of 64-bit Ubuntu 14.04 LTS DOES NOT have the capability of running 32-bit applications, instead you must manually install the necessary packages by executing the following:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
First you need to download Android Studio. Point your web browser to here - click on the 'Download Android Studio' button. On the next page that appears, and under the 'All Android Studio Packages' section, click on the file for the Linux platform.The terms and conditions page will appear - if you have agreed with it, select the the radio button that says so, then click on the blue button to start the download. Save the zip file and wait for the download to finish.
Start a terminal and from your home directory, execute the following command:
unzip Downloads/android-studio-ide-135.1641136-linux.zip
This will decompress the contents of the zip file downloaded from your Downloads directory into a new directory called 'android-studio'.
To start Android Studio setup, execute the following commands, one by one:
cd android-studio/bin
./studio.sh
A window similar to the one shown below will appear asking whether you would like to import any settings.
If this is the first time you are using Android Studio, it will be likely that you don't have anything to import. However, if you are moving from an older version of Android Studio, you may want to keep any settings made previously - in this case specify the location of the settings and let the setup wizard do the job.
Click on the OK button to proceed. Android Studio will begin loading as shown in the figure below.
After a while, the Setup Wizard screen similar to the one shown below, will appear. Click on the Next button to continue.
The wizard will start off by trying to detect where Java is installed - if you have installed and set up Oracle's Java in /usr/lib/jvm, then the wizard will find it and the next screen shown will appear.
The Standard type of setup is already selected - this is recommended unless you want to customize the setup. Click on the Next button and the the next screen will appear.
If you are using Ubuntu 14.04 and you have Virtualization Technology (vt-d) enabled in your PC BIOS and Linux kernel, then it will be detected as shown on the wizard's screen. You can read up more on this technology at the URL shown on the screen - just remember that the web page there is for Windows only - to read more on Linux and Virtualization Technology, click here. Then click on the Next button.
The next screen that appears as shown below is where you agree to accept the license for installing Google's Android SDK. Note that this is a must and cannot be skipped if you want to develop software for the Android platform. Click on Accept and the the Finish button.
The SDK components will begin downloading as shown in the next screen.
Once downloading and installation is completed, a log window will appear as shown. Note that, if you are using a 64-bit Ubuntu 14.04 LTS and did not install the required 32-bit packages, an error message about being unable to create an Android virtual device will appear on the last line. Click on the Finish button.
The next screen shown is the Android Studio IDE itself (shown below). You have now successfully installed Android Studio on your Ubuntu 14.04 PC.
Notice the 'Check for
updates now.' on the IDE window - click on Check and if there are any
updates, a window similar to the one shown below will pop up.
Click on the Update and Restart button. Android Studio will close and the updates will begin downloading as shown.
Do not close the Android Studio IDE window yet. There is one more thing to do before you can start to use Android Studio. Remember that, at the moment, you have to start a terminal, change to the correct bin directory and then launch studio.sh in order to start Android Studio. Surely there must be an easier way and there is! But, in order to setup the easier way, there are several things that must be done.
The first is to create a launcher item in the Unity launcher. This is easily accomplished by right-clicking on the Android Studio icon in the launcher and click on the 'Lock to Launcher' item. The Android Studio launcher (as shown by the green arrow in the screenshot below) will then remain permanently in the launcher until you remove it - but remember that the Desktop Entry for the launcher will still need to be edited before it can work properly.
The second is to edit the Desktop Entry text file for the Android Studio launcher. Launch a terminal and execute the following:
nano .local/share/applications/jetbrains-android-studio.desktop
Remember that this command is all on one line and don't forget the dot (or period) before local - this is NOT a typo as .local is a hidden file. The contents of that file need to be edited as follows:
a) Remove the 'Setup' from the 'Name' item.
b) Edit the 'Exec' item to /home//android-studio/bin/studio.sh (replace with your login name - in case you forgot, this is the same login name as the 'Path' item in the previous line). Note that the unedited line is for the setup command and is rather long - make sure that you remove it completely before entering the new command.
c) Insert a line after the 'Exec' line, and type 'Terminal=false'.
Leave the rest of the items unchanged. The final file will look something like this:
Save the file and exit nano. To test whether the launcher works, first close Android Studio and then click on the launcher - Android Studio should re-open. If not, check your Desktop Entry file again.
If you want to launch Android Studio from anywhere using 'studio.sh', it is recommended that the system wide path include the android-studio/bin. To do this, execute this command in a terminal:
sudo nano /etc/profile
In the 'profile' file make sure to include the android-studio/bin in the PATH - for example:
export PATH=$PATH:$HOME/android-studio/bin
Save the file and close nano. To make sure that this new path takes effect, log out and then log in again. Now you can launch 'studio.sh' in a terminal from any directory.
That's it - you are now ready to use Android Studio for developing software on the Android platform.
So you have installed a brand-new Ubuntu 14.04 LTS OS on your PC and tweaked it just the way you like it. Now you want to do a bit of Java programming on it and wonder how to
go about doing it. Let this article be the guide to show you how to install Oracle's JDK 8 Java and set it up properly.
First you should be aware that there is no Java installed on a freshly intalled Ubuntu 14.04 LTS. This can be verified easily by executing 'java -version' in a terminal. This article assumes that there is no Java installed.
Why Oracle Java? Why not OpenJDK? Good question and the answer is that it is recommended by Google. Should you plan to use Java for Android programming later, then Google says it is better to use Oracle's version - their Android Studio says that there are stability issues with OpenJDK. Whether this is true is a moot point here - if you do plan to do Android programming later, then install Oracle's Java - else, any Java will do, even OpenJDK.
Here are the steps for installing Oracle JDK 8. Note that a web browser is used to download the JDK - not Ubuntu Software Center or Synaptic.
- Point your browser to here and click on the JDK download button (not the Server JRE or JRE). On the page that appears next, click to 'Accept License Agreement' and select either the 32-bit or 64-bit tar.gz file to start the download. Save the file and wait for the download to finish. If you have not changed anything, the JDK file will be found in your Home folder Downloads location.
- On the same web page, scroll down and click on either the 32-bit or 64-bit Demo and Sample file for downloading. Again, save the file and wait for the download to finish,
- Use the 'Back' key for your browser to go back one page and scroll down until you see Java SE 8 Documentation and click on the download button. On the next page, accept the license agreement and click on download the zip file for the documentation for the JDK (not the JavaFX). Save the file and wait for the download to finish.
Now that you have downloaded the files, it's time to install it. First open a terminal and change directory to the Downloads folder (or to the folder in which you saved the downloaded JDK files) by executing:
cd Downloads
Then extract the contents of the 'jdk-8u25-linux-x64.tar.gz' file by executing:
tar xzvf jdk-8u25-linux-x64.tar.gz
This will create a 'jdk1.8.0_25' directory in the Downloads directory while displaying a lot of stuff on the terminal's screen. After this is completed and you are back to the command prompt, you can extract the demos and samples by executing:
tar xzvf jdk-8u25-linux-x64-demos.tar.gz
This will create 2 directories under the 'jdk1.8.0_25' directory - 'sample' and 'demo' directories. When completed, you can now extract the Java API documents by executing:
unzip jdk-8u25-docs-all.zip -d jdk1.8.0_25
This will create a 'doc' directory under the 'jdk1.8.0_25' directory. After this is completed, you now have all the files necessary for the Oracle Java JDK 8 - all you have to do is to put them in the proper place.
The 'proper place' can be anywhere - your home directory (if you want Java for your own use only) or '/usr/local/' or 'usr/lib/jvm', etc. Note that if you want Java to reside as a sub-directory in '/usr/local/' or '/usr/lib/jvm/', then you need to use 'sudo' since administrator privileges are needed to create sub-directories there. This is not required if you install Java in your home directory. For this article, we will use '/usr/lib/jvm/' directory as this is where all Java related files end up if it was installed by default.
First we have to create the /usr/lib/jvm directory by executing:
sudo mkdir /usr/lib/jvm
Next, we move the
'jdk1.8.0_25' directory to /usr/lib/jvm
sudo mv ~/Downloads/jdk1.8.0_25/ /usr/lib/jvm/
The directory will be moved from your home Downloads directory to the '/usr/lib/jvm/' directory. You can verify this by listing the contents of the 'usr/lib/jvm/' directory using the 'ls -la' command. Note that the owner and group for the jdk1.8.0_25 directory is yours but you can easily change this by executing:
sudo chown -R root:root /usr/lib/jvm/jdk1.8.0_25
Again, you can verify this by using the 'ls -la' command.
The next thing to do is to tell Ubuntu where Oracle Java JDK resides. For this we use the 'update-alternatives' command. Execute the following commands one by one from the terminal (note that all commands are on a single line):
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_25/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_25/bin/javac" 0
These will install all the necessary links to Oracle's Java. Next we have to tell Ubuntu the default Java to use. Execute the following commands one by one from the terminal (note that all commands are on a single line):
sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_25/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_25/bin/javac
To verify that all have been set correctly, you can use the following commands:
update-alternatives --list java
update-alternatives --list javac
If the output to the 2 queries above are /usr/lib/jvm/jdk1.8.0_25/bin/java and /usr/lib/jvm/jdk1.8.0_25/bin/javac, then everything have been set correctly. Now that you have informed Ubuntu about Oracle's Java, you still have to perform one last task before Java is set up and ready for use. This is to set the environment variables and paths correctly for the whole system. Execute the following command:
sudo nano /etc/profile
This will execute the nano text editor and open the /etc/profile file for editing. Now add the following lines at the end of the file.
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25
export PATH=$PATH:$JAVA_HOME/bin
Save the file and close it. Note that, upon system startup, these will set the JAVA_HOME and PATH environment variables for the whole system. The JAVA_HOME environment variable points to the JDK root while the PATH environment variable will add the /bin directory of the JDK to whatever path that has already been specified. This will enable the 'javac' command to be executed from any directory.
Now log out and then log in again to the Ubuntu system in order to make sure that both the environment variables is set. Check by opening a terminal and executing:
echo $JAVA_HOME
echo $PATH
Then as the last check, execute the following:
java -version
javac -version
If you see 'java version "1.8.0_25"' and 'javac 1.8.0_25' in the output, then you are now ready to use Oracle's Java on your Ubuntu system. You can also delete the tar.gz and zip files which were downloaded from the web in order to free up disk space.
Where to go from here? If you are familiar with Java programming, you can go ahead to use Java anyway you like it. If you are a novice and this is the first time you are using Java, then I would recommend searching the web for tutorials and the books "Java For Dummies, 6th Edition" and "Head First Java, 2nd Edition" as a guide. Happy Computing!