Node.js Tutorial #2: How to Install Node.js

In my previous Node.js tutorial I went over what Node.js is and how it can help you become a better, more modern front end designer. If doing this is something you're interested in, it's probably time to get started with Node. This article will help you do just that.

Welcome to my tutorial on how to install Node.js on Windows and Linux.

A quick foreword

Before getting started, it's important to mention this:

Node.js works best on Linux - there's no way around it.

Linux has by far the best performance, integration and support available. It's followed by Mac with Windows last. This is probably why most of the information you'll find on Node is written with Mac or Linux in mind.

If you're working Node.js with Windows, I would highly suggest installing Linux as it'll save you countless hours spent solving problems caused by Windows itself.

How to install Node.js on Windows

There is a native version of Node for Windows that integrates with the command prompt. While it doesn't behave exactly like Linux or Mac would, it does work.

However, I would suggest the further, more fruitful option of WSL, which will essentially install Linux within Windows. Using this workaround means that Node will run exactly as it does on Linux.

WSL: a temporary solution

The Windows Subsystem for Linux (or WSL) is an implementation of Linux inside Windows. This is Microsoft's effort to make Windows a more viable platform for development, among many other things.

In Layman's terms, WSL allows you to access a full Linux system without ever leaving Windows, thanks to a command-line interface. In theory, this would be the perfect solution to using NodeJs inside Windows.

As much as I appreciate the efforts Microsoft has made here, WSL is painfully slow. Actions that would take less than a second on a native Linux installation can take minutes on Windows. It's not great and it's still quite buggy, but it works well enough to be the best option to choose from.

If you're interested in waiting a bit longer, Microsoft is planning to release a WSL2, which is rumoured to be just as fast as Linux. But until then, let's get into WSL.

Enabling WSL and installing Windows on Linux

WSL is available in Falls Creators Update of Windows 10. If you own even an unregistered copy of Windows 10, you probably have this by now. The steps are fairly simple, though not terribly obvious:

  • Open your settings menu.

  • Click on "Apps" and scroll all the way down until you find "Programs and Features"

  • In "Programs and Features" click "Turn Windows Features on or off" in the left menu.

  • In the pop-up that should appear, scroll until you find the option for "Windows Subsystem for Linux. Once you've pressed okay, you'll be asked to restart Windows.

  • After restarting, open the Microsoft Store App and search for Linux. There are lots of options you can choose from, but unless you're familiar with Linux I suggest you go with Ubuntu.

  • Install it like any other App.

Installing Node.js

The installation process is pretty straightforward if you're using Linux or WSL. Depending on which Linux distribution you're running, there are many different ways to install Node.js. I won't make a tutorial for all of them, but they can be found on the Node.js website.

If you followed the above tutorial to install Ubuntu within WSL (or you are just running Ubuntu) the installation is as follows.

On Windows: Open Ubuntu from the Start Menu
On Ubuntu: Open the terminal (CTRL+T)

And run this command:

curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs

This command will download the Node.js source with curl (which is a very useful library you'll end up using a lot) and installs it using apt, which is Ubuntu's Package Manager.

To make sure Node.js and NPM (Node package manager) are installed run two further commands. If they are installed correctly they should output a version number.

leonardo@DESKTOP-4NMDS80:~$ node -v                                                                                     v13.2.0                                                                                                                 leonardo@DESKTOP-4NMDS80:~$ npm -v                                                                                      6.13.1

Working with Linux and its terminal

I'm sure if you're not already used to using a terminal interface you're probably hesitant to progress and that's fair. Command line interfaces can be tricky to use and a lot of the time they have terrible UX. But if you're planning to do even a little web development or even run your own site, it's essential.

Don't worry, it's actually fairly simple once you understand some of the basics.

Here's some important tips you should know:

  • When you open the terminal you will always be located in your user's home folder, which is located at /home/youruser.

  • You can use the cd command to move between folders.

    • cd / will bring you to your root folder (the highest folder in your hierarchy which contains everything else).
    • If you type cd home after moving to your root folder you will move into the home folder. You can use this for any folder currently contained in the folder you're in.
    • cd .. will bring you up one level from the folder you're currently in.
  • ls will list all the folders and files in the folder you're in.

  • Putting sudo in front of every other command will run it as the Linux equivalent of an "Administrator". This will be useful whenever you get an permission error.

These basic tips should be more than enough to play around with as you get started. There's a lot more to learn of course, but you'll learn as you go along. And don't forget that Google will have most of the answers to any questions you have.

Seriously start learning how to Google properly, it's nothing short than essential to work with any web technology.

And if you still can't find the answer you're looking for, don't be afraid to ask on related forums or comment sections of articles (like this one!).

Conclusion

Learning Node.js and Linux might seem like big, scary tasks that will take you years to complete. And while that might be true, it's also true that you will most likely be able to use both for something useful in just a few months. And the satisfaction of gaining new skills should take any scariness out of it.

One you start using both of these tools, you'll continuously learn how to use them better and better.

In the next tutorial I'll go over how Node.js and its package manager work. I will also explain how to set up your first basic web app, along with Node.js' limits and possibilities.