This is the most basic task that needs to be done before writing Java programs. I had written a couple of basic posts on Java to explain the basics which also includes downloading and installing Java. Goal of this post is to list down steps to do so. This will be kept as a reference for all future posts.
Previous related posts
- Download suitable Java distribution from oracle site.
- Run the installer.
- For Windows simple run the .exe file.
- For debian based system you can simply
execute sudo apt-get install oracle-java7-installer
from command line.
- Next we need to add JAVA_HOME environment variable. Though not required for running standalone java programs. Many other software's use this to locate Java installation. To do so follow the steps
- Open the System control panel
- Open Advanced tab
- Click on the Environment Variables button
- Add a new System variable with the name JAVA_HOME. Value should be the directory Java was installed in (something like C:\Program Files\Java\jdk1.7
- Refer How to permanently set $PATH on Linux?
- Path is above post is different, You should add your Java installation path (Something like /home/user/java/jdk1.7/bin)
- For windows when you run the installer java will be automatically added to %PATH% variable. You can easily verify that by executing following in cmd - java -version. If not added you can do so by adding %JAVA_HOME%\bin to your system path (assuming you followed step 3 else provide complete path).