Wednesday, September 20, 2023

How to set path after java installation?

Setting the PATH environment variable after installing Java is necessary to ensure that your system can find the Java executable files (e.g., java, javac) when you run them from the command line. The steps to set the PATH variable vary depending on your operating system. Below are instructions for the most common operating systems:

Note: Before proceeding, make sure you have Java installed on your system. You can verify this by running java -version in your command prompt or terminal. If Java is installed, it should display the version information.

Setting the PATH Variable on Windows:

  1. Right-click on "This PC" or "My Computer" (depending on your Windows version) and select "Properties."

  2. In the System window, click on "Advanced system settings" on the left sidebar.

  3. In the System Properties window, click the "Environment Variables" button.

  4. In the Environment Variables window, under "System variables," locate the "Path" variable and select it. Click the "Edit" button.

  5. In the Edit Environment Variable window, click "New" and add the path to the "bin" directory of your Java installation. The path is typically similar to this, but it may vary depending on your Java version and installation directory:


    C:\Program Files\Java\jdk1.8.0_301\bin

    Make sure to adjust the path according to your Java installation.

  6. Click "OK" to close each of the open windows.

  7. Open a new Command Prompt window and run java -version to verify that the PATH variable has been set correctly, and Java is recognized.

Setting the PATH Variable on macOS and Linux:

You can set the PATH variable temporarily for the current session or permanently in your shell's configuration file (e.g., ~/.bashrc, ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bash_aliases, depending on your shell).

Here's how to set it temporarily for the current session (this change will be lost when you close the terminal):


export PATH=/path/to/java/bin:$PATH

Replace /path/to/java with the actual path to the "bin" directory of your Java installation.

To make the change permanent, you can add the above line to one of the shell configuration files mentioned earlier. Here's an example of how to do it using the .bashrc file:

  1. Open a terminal.

  2. Open the .bashrc file in a text editor (e.g., Nano or Vim) with the following command:


    nano ~/.bashrc
  3. Add the export line at the end of the file:


    export PATH=/path/to/java/bin:$PATH

    Replace /path/to/java with the actual path to the "bin" directory of your Java installation.

  4. Save the file and exit the text editor.

  5. To apply the changes immediately, run:


    source ~/.bashrc

    Now, Java should be accessible from the command line.

Remember to adjust the instructions above if you're using a different shell or shell configuration file.

No comments:

Post a Comment

Solitude by the Seaside A Single Man's Moonlit Musings.

In the quiet of the night, under the gentle glow of the moon, a solitary figure sits by the sea. The rhythmic crash of the waves against the...