02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Setting up Node.js and NPM on a Linux System

Setting Up Node.js and NPM on a Linux System

In this tutorial, we will walk you through the process of setting up Node.js and NPM on a Linux system. If you're using a Linux distribution like Ubuntu, Fedora, or Debian, this guide will help you get started with Node.js development. Setting up Node.js on Linux provides you with a powerful and flexible environment to create full stack React applications. This tutorial was created in 2016, and any significant updates have been included to keep the information current.

Step 1: Update Your Package Manager

Before installing Node.js, it’s a good practice to update your package manager to ensure you have the latest versions available. Open your terminal and enter the following commands:

sudo apt update
sudo apt upgrade

These commands will update your system’s package information and upgrade the installed packages to their latest versions.

Critical Update (2024): It is now recommended to use apt full-upgrade instead of apt upgrade for more comprehensive package upgrades that involve removing or updating dependencies.

Step 2: Installing Node.js and NPM

You have several options for installing Node.js on Linux, including using the package manager, a NodeSource repository, or nvm (Node Version Manager).

Method 1: Installing Node.js from the Default Repositories

The simplest way to install Node.js is from the Linux package manager.

  1. Install Node.js and NPM:

    sudo apt install -y nodejs npm
    
  2. Verify the Installation:

    node -v
    npm -v
    

    These commands will display the installed versions of Node.js and NPM, confirming a successful installation.

Method 2: Installing Node.js via NodeSource

For the latest versions, it’s often better to use the NodeSource repository.

  1. Add NodeSource Repository:

    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    

    Replace 16.x with the version you want to install (use setup_18.x for the latest LTS).

  2. Install Node.js:

    sudo apt install -y nodejs
    

Critical Update (2024): It’s now common to use Node.js version 18 or higher for full compatibility with the latest JavaScript features and security updates.

Step 3: Using Node Version Manager (nvm)

Another popular method for installing Node.js is by using nvm. This allows you to manage multiple versions of Node.js and switch between them easily.

  1. Install nvm:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
    
  2. Load nvm (you may need to restart your terminal or run the following command to load nvm):

    source ~/.nvm/nvm.sh
    
  3. Install Node.js using nvm:

    nvm install 16
    

    Replace 16 with the version number you want to install.

  4. Verify the Installation:

    node -v
    npm -v
    

Critical Update (2024): nvm is now the recommended way to manage Node.js versions on Linux, especially if you work on multiple projects requiring different versions of Node.js.

Step 4: Configuring Node.js for Development

After installing Node.js and NPM, there are a few steps you can take to configure your development environment:

  • Global Packages: Install packages like nodemon and npm-check-updates globally to help with development tasks.

    npm install -g nodemon npm-check-updates
    
  • Permissions Issue: On Linux, you might encounter permission issues when installing packages globally. You can either use nvm, which avoids this problem entirely, or fix permissions by setting up npm to use a directory in your home folder for global installs.

Conclusion

Setting up Node.js and NPM on a Linux system provides a flexible and powerful environment for building modern applications. In this tutorial, you learned different ways to install Node.js, including the default repositories, NodeSource, and using nvm for version management. We also covered some essential configurations to get your environment ready for development.

Linux is a great platform for development, and with Node.js set up, you are now ready to start building scalable, full stack React applications. Remember, it's best to use nvm for managing Node.js versions, as it makes switching between different projects and maintaining compatibility much easier.

Video Transcript

00:00The next step we're gonna talk about right now is setting
00:03up no js and NPM on your server.
00:06Now, you don't have to do the sta step right away.
00:09You could keep this video later down the line once you're
00:12ready to put something up on a server,
00:14but I encourage you to check it out.
00:16Now, by the way, the, the main reason is
00:18'cause I wanted all the installation
00:19and setups to be clustered in the same place.
00:21So they'll be easy to access down the line
00:24as you look back into your library.
00:26So you don't have to do this right now,
00:28but in this lecture what we're gonna go ahead is we're gonna
00:30show you one of the different ways that you could set up NPM
00:34and node JS on your server.
00:35Namely, we're gonna work with a package manager.
00:38And in my case, because I'm running on a Santos,
00:41I'm gonna be using Yum.
00:42But I'm also gonna show you how do you do it
00:45with other operating systems.
00:47So by the end of this lesson, we're gonna extend Santos.
00:50We're, we're gonna even extend the Santos package manager
00:53to show you how to install no JS
00:56and NPM using Yum.
01:00Congratulations. We're done with installation.
01:03Thanks for your desktop
01:04to set up our development environment.
01:07That was easy. Now, if you don't have the strength
01:10to do this now, then you could skip ahead
01:12and continue with the development,
01:14but then come back to this video.
01:16But I wanted holistically
01:17to put all the installations together.
01:19In this video, I wanted to talk about the installation
01:23of no JS on a live server.
01:25'cause end of the day, you're gonna want it
01:27to run on a real server, not only on your operating system.
01:30There, it's a little bit different,
01:32but we're gonna choose, for example, uh, I'm gonna go
01:35and log in right now.
01:36I'm gonna SSH and log into my server.
01:39Um, and I'm gonna go, oops, there we go.
01:44Not my server, but I'm gonna SSH into my server
01:47and now I'm inside of my server.
01:49Now the steps involved with installation.
01:51I'm not running the server as a Linux based server.
01:55It's a CentOS based server. More accurately.
01:58What I want to do is I want to approach the yum,
02:00yum repository
02:02and install, first of all, the EPEL
02:05re release now the EPEL release
02:09and extends the native available packages
02:13that are installable through yum.
02:16Now we're gonna talk very soon about what NPM is.
02:19And by the way, what NPM is is really parallel
02:24to what Yum is.
02:25So if you're already familiar with yum,
02:27then NPM is gonna be really easy.
02:30Now, if you're not familiar, but you already have a server
02:32and you're running it through terminal,
02:34then this is gonna be a really great bonus
02:36because you're gonna get a better grasp,
02:38a better understanding of what Yum is.
02:41And I'm gonna go ahead and just type my server password
02:44and it's gonna go through the process.
02:46And right now it's telling me
02:47that I already have EPL release six eight,
02:50it's already installed and it's an
02:52already in the latest version.
02:53So that's it. I'm already set with, uh,
02:55with the EPL release, so I don't have to worry about that.
02:59Once I have that installed, the next step is to go ahead
03:02and actually go ahead and I'm gonna go
03:04and install OSU the no js.
03:06So I'm gonna go ahead and call your pseudo Yum install,
03:10and I'm gonna type no js.
03:11Now even before we go through and type enter,
03:13I just want you to get a good sense of what this means.
03:16Psdo on the server on Linux basically says I'm asking
03:20for permission to run as the root.
03:23So we're basically running with full permissions.
03:26That's why also we're prompted for a password in,
03:28in my case, my user
03:30that I'm currently in is an administrator, so he has access
03:33to the root features.
03:35So I just have to type in my password to confirm
03:37that I really wanna run this operation with the full access,
03:41with the full granted rights.
03:43Yum is a package manager that runs on on CentOS
03:48that enables us to install a lot of things just
03:50by typing on the terminal.
03:52And we're gonna talk a lot more about what
03:54that actually means when we're gonna be talking about NPM.
03:57Literally probably in the next lecture.
04:00And install is a, is a command that asks us
04:02to install something and then we list out
04:04what we want to install.
04:06So in this case, we wanna install node js.
04:08Now once I type enter, what's actually gonna happen,
04:10it's gonna go through the repository and search for node js.
04:15And you could see that it's asking me if found two packages,
04:18it has a dependency.
04:20So we need to have both node js installed
04:23and oso the lib UV installed.
04:26And you can see that the version that is available
04:28for our server is zero point 10.42.
04:33I'm gonna go ahead and I'm gonna click on yes,
04:35I want to get this installed.
04:37I want this package and it's gonna install both packages,
04:41download them, install them, and configure them.
04:42And that's it. We have node js installed.
04:46Last but not least before we conclude this lecture, contrary
04:50to desktop applications that install node js in concurrent
04:54with N-P-M-N-P-M needs to be installed separately.
04:58And to do that I'm gonna type again, pseudo yum install,
05:01but this time I'm gonna ask for NPM.
05:04Once I do that, it's gonna give me access.
05:06OSU for NPM, it's searching for it.
05:08Now it's telling me there's 99 packages that I need
05:10to have updated or installed for NPM to actually work.
05:15So these are the NPM needs, all of these dependencies
05:18to get it installed.
05:20In my case, because I'm not really running it on my server,
05:22I'm not gonna go ahead and install it right now
05:24because I don't really want to update
05:26and install all these packages at the moment.
05:29But once you're ready to go to production,
05:31you definitely want NPM and you definitely want node js
05:34and you're gonna want both of them installed on your system.
05:37And again, the process involved
05:39with checking if node js was installed
05:41and working is just typing node minus via new,
05:44you'd get the version number if everything is configured.
05:47Same is true with NPM.
05:49As you notice on my server, I didn't install NPM,
05:52so I'm not gonna get that command back.
05:54But if I exit my server and go back into
05:56My, into my, um, operating system, my terminal of Mac,
06:01if I go ahead here and type NPM minus V,
06:04we should get a version number telling us
06:06that we have NPM version 3.93 installed on our system.
06:11So there you go. That's how you install, configure,
06:13and set up no JS
06:15and NPM on desktop Windows, Mac, and on your server.
06:22In this lecture we used Yum to install no JS and NPM,
06:26but the version that we installed was a very early version
06:29that is not the latest.
06:31In the next lecture,
06:32what we're gonna do is we're gonna take a look at
06:34how do you update the version, making sure
06:37that you have a more concurrent version of NPM and no js.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!