Getting Started with JavaScript on Linux

Setting up JavaScript development on Linux is simple with Node.js and Visual Studio Code. This guide will walk you through the process so you can start writing and running JavaScript code right away.


Step 1: Install Node.js

To run JavaScript outside the browser, you'll need Node.js. Here's how to install it on your Linux machine:

  1. Open your terminal (you can use Ctrl + Alt + T or search for "Terminal" in your application menu).
  2. Install Node.js using your package manager. You can install the LTS version (recommended) by running the following commands:
    sudo apt update
    sudo apt install nodejs npm
  3. Enter your password when prompted and follow any additional prompts to complete the installation.

Step 2: Verify Installation

After installation, verify that Node.js and npm (Node Package Manager) were installed correctly:

  1. Open your terminal and run the following commands one at a time:
    node --version
    npm --version
  2. If both commands return version numbers, you're ready to go!

If Node is correctly installed, you will see the version of Node displayed in the terminal, something like:

For Node.js version:

v22.x.x

For npm version:

10.x.x

Step 3: Install Visual Studio Code

We recommend using Visual Studio Code (VS Code) as your editor. It's lightweight, powerful, and perfect for JavaScript development.

  1. Open your terminal and install Visual Studio Code by running the following commands:
    sudo apt update
    sudo apt install software-properties-common
    sudo apt-add-repository ppa:ubuntu-desktop/ppa
    sudo apt update
    sudo apt install code
  2. Once installed, you can open Visual Studio Code by typing code in your terminal or by searching for it in your application menu.

Step 4: Run Your First JavaScript Program

  1. Open VS Code and create a new file named app.js.
  2. Type the following code:
    javascript
    console.log("Hello, JavaScript!");
  3. Save the file to an easily accessible location, such as your Desktop or Documents folder.
  4. Open your terminal, navigate to the folder where the file is saved using the cd command, and run:
    node app.js
    You should see the following output:
    Hello, JavaScript!
  5. 🎉 Great job! You've successfully created and run your first JavaScript program on Linux.

That’s it! You’re now ready to explore the world of JavaScript development on your Linux machine. Happy coding!


Frequently Asked Questions

Do I need to restart my computer after installing Node.js on Linux?

Usually not. But if your terminal doesn't recognize the node or npm command, try restarting your terminal or logging out and back in.


What is Node.js and why do I need it on Linux?

Node.js is a JavaScript runtime that allows you to run JavaScript outside the browser. It's essential for local development and working with JavaScript tools.


How do I check if Node.js is installed on Linux?

Open a terminal and run node --version and npm --version. If version numbers appear, Node.js and npm are installed correctly.


Can I use a different code editor than VS Code on Linux?

Absolutely. You can use any code editor like Sublime Text, Vim, Atom, or others. VS Code is popular due to its rich feature set and extensions.


How do I run JavaScript files from the Linux terminal?

Navigate to the directory containing your JavaScript file using the cd command and then run it using node filename.js.


What if the node command is not recognized on Linux?

This might mean Node.js was not installed correctly or isn't in your PATH. Try reinstalling using NodeSource or a package manager like apt or nvm.