Change Java Runtime

Most of the time as java developer, one of the first thing you do to set up on you new computer is java environment. This is basically telling your cmd (windows) terminal (mac or Linux) where to find the java.

java / javac (the compiler) is all under your java installation directory.

We assume that you have successfully downloaded and installed the JDK or JRE. If you are a developer we suggest you to download the latest JDK (Java Developer Kit).

Steps

On Windows

  1. Click Start then right Click on "Computer" and choose "Properties."
  2. On the new window click "Advance system settings."
  3. Choose "Environment Variables."
  4. Create variable with the following properties: name: JAVA_HOME , value: your path to jdk
  5. Update the PATH variable by appending %JAVA_HOME%\bin at the end
  6. Click the Save button
  7. Click Start > new > cmd
  8. When you type following you should see the newly installed java version
    • java -version

Linux

  1. in your .bashrc or .bash_profile file append following
    • export JAVA_HOME=<your-java-dir>
    • export PATH=$PATH:$JAVA_HOME/bin
  2. save the file
  3. in terminal type:
    • . .bash_profile or . .bashrc (note that you have a space) this tells your terminal to load the updated file in current terminal so you get the newly created java in your path
  4. You should see java version printed when you type following:
    • java -version

Related Articles