By default, Ubuntu does not come with Java (or the Java Runtime Environment, JRE) installed. However, you may need it for some programs or games like Minecraft. We will show you how to quickly and easily check if Java is installed and how to install it.
Note that Java can be vulnerable to security problems, and you should protect yourself. If you really need Java for programs or games that you run, read our article about protecting yourself from Java security problems.
NOTE: When we say to type something in this article and there are quotes around the text, DO NOT type the quotes, unless we specify otherwise.
To check which version, if any, of Java is installed, type the following at the prompt and press Enter.
If you get a result similar to the one shown in the following image, you do not have Java installed. The list shows you which packages in your system have Java available and the command for installing java is displayed.
However, before installing Java, let’s make sure all the packages are up to date. Type the following at the prompt and press Enter.
sudo apt-get update
This updates all the packages in available in Ubuntu. Type your password at the prompt and press Enter.
When the update is done, choose which a package from the list to install java. In our example, we installed version 6. Type the following command at the prompt and press Enter.
sudo apt-get install openjdk-6-jre-headless
Replace the last part of the command after install with the package from the list that you chose.
Because you recently ran another command as root using sudo, you are not asked for your password again.
The progress of the installation displays and then a message displays saying how much disk space will be used. When asked if you want to continue, type a “y” and press Enter.
When the installation is done, check the version of Java again by typing “java –version” at the prompt and pressing Enter. You’ll see a result similar to the following indicating the version of Java you just installed.
If you only need Java for desktop programs and games, it’s a good idea to disable Java browser integration. Again, see our article for instructions on how to do this.