Setting the environment variables for JAVA_HOME, NODEJS

Related Courses

Setting up environment variables like JAVA_HOME and NODEJS is a key step in configuring your development environment properly. Here's how you can do it for Windows, Linux, and macOS:

? For Windows (10/11)

✅ Steps to Set JAVA_HOME and NODEJS:

  1. Find the installation paths:

    • Java: Usually something like C:\Program Files\Java\jdk-XX

    • Node.js: Something like C:\Program Files\nodejs

  2. Set Environment Variables:

    • Press Win + S, type Environment Variables, and open it.

    • Click Environment Variables…

    • Under System variables, click New:

      • Name: JAVA_HOME

      • Value: path to your JDK folder (e.g., C:\Program Files\Java\jdk-17)

    • Add another variable for Node.js if needed:

      • Name: NODEJS

      • Value: C:\Program Files\nodejs

      • Update the Path variable:

        • Select the Path variable under System variables → Click Edit.

        • Click New and add:

          • %JAVA_HOME%\bin

          • %NODEJS%

      • Apply and Restart Terminal:

        • Open a new Command Prompt or PowerShell window.

        • Check with:

          echo %JAVA_HOME%
          java -version
          node -v
          

? For Linux/macOS (Bash or Zsh)

Open your shell profile:

  • For Bash: nano ~/.bashrc or ~/.bash_profile

  • For Zsh: nano ~/.zshrc

Add the following lines:

# Java
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

# Node.js
export NODEJS=/usr/local/bin/node
export PATH=$NODEJS:$PATH

? Adjust the paths according to where Java and Node.js are installed.

Then apply changes:

source ~/.bashrc  # or source ~/.zshrc

Verify:

echo $JAVA_HOME
java -version
node -v