How To Install Node.js On Ubuntu 18.04
Introduction
Node.js is a powerful, open-source JavaScript runtime environment designed to enable the implementation of server-side JavaScript code. It's a cross-platform package that allows developers to run JavaScript code on a machine like a standalone application. The platform is primarily used to create robust back-end, server-side applications, but it's also useful as a front-end solution.This tutorial will help you install Node.Js on Ubuntu 18.04 Bionic Beaver Linux via three options: from Ubuntu repository, from NodeSource repository, and using the Node Version Manager (NVM).
Part 1: Installing Node.js From Ubuntu 18.04 Repository
Node,js is a reliable package that is available from the repository of latest distribution of Ubuntu (18.04). In the first part of this tutorial will install Node.js and the Node.js Package Manager (NPM) from Ubuntu 18.04 repository.Step one - Installing Node.js
First, update the packages index, then install the Node.js:- $ sudo apt update
- $ sudo apt install nodejs
- $ nodejs --version
- v8.10.0
Step 2 - Installing Node.js Package Manager (npm)
Installing Node.js Package Manager makes it easy to download npm packages. Run the command below to install npm:- $ sudo apt install npm
- $ npm --version
- 3.5.2
Part two: Installing Node.js From NodeSource Repository
NodeSource is a popular company that offers enterprise-class Node support. The company maintains a reliable repository that features the most recent version of Node.js. Follow the steps below to install Node.js package and npm.Step 1 - enabling NodeSource Repository
Execute the command below to activate the NodeSource repository:- $ curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
Step 2 - Installing Node.js as well as the npm
By now the NodeSource repository is activated, and the stage is set for Node.js installation. Run the command below to install Node.js and the npm:- $ sudo apt install nodejs
- $ node --version
- V8.11.3
- $ npm --version
- 5.6.0
Part 3: Installing Node,js using the Node Version Manager (NVM)
NVM is a helpful bash script that is phenomenal at managing numerous versions of active Node.js. With NVM, it's a breeze to install or uninstall a specific version of Node.js you want to use. In this part of our tutorial, we’ll utilize NVM to install Node.js on Ubuntu 18.04.Step 1- Downloading NVM Script
Execute the command below to download the install script for NVM:- $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
The output of the download-nvm-script will look like this:
- => Close and reopen your terminal to start using nvm or run the following to use it now:
- export NVM_DIR="$HOME/.nvm"
- [ -s"$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
- [ -s"$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Once you add the script to your PATH, run the command below to verify nvm installation:
- $ nvm --version
- 0.33.11
Step 2 - Using NVM To Install Node.js
The NVM is successfully installed which means, we can easily install Node.js. Run the command below to install Node.js:- $ nvm install node
- $ node --version
- v10.6.0
- $ nvm install --lts
- $ nvm install 4.9.1
- $ nvm ls
From the above output, you can clearly see that v4.9.1 is the Node.js version utilized in the current session. Besides, its clear v10.6.0 is the default version; this Node.js version will be active once a new shell is opened.
You can run the command below to switch the current active Node.js version:
- $ nvm use 8.11.3
- $ nvm current
- V8.11.3
- $ nvm alias default 8.11.3
Part 4: Further Implementations
Installing Development Tools
If you want to compile or install native add-ons from the Node.js Package Manager, you must install the required development tools. Now, execute the command below to install the required packages:- $ sudo apt install gcc g++ make
Uninstalling Node.js
Run the command below, to uninstall npm packages as well as Node.js:- $ sudo apt remove nodejs npm
Installing The Yarn Package Manager
Yarn is a helpful JavaScript Package Manager that integrates seamlessly with npm. The package is developed to remedy a plethora of issues with npm such as reducing network connectivity errors and speeding up the installation process.To install Yarn, we’ll use the apt commands:
Step 1- Adding Yarn Yum Repository
Execute the commands below to add a GPG key and a repository:- $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
- $echo"deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Step 2 - Installing Yarn
Since the repository has been added successfully, you can now run the following commands to install Yarn:- $ sudo apt update
- $ sudo apt install yarn
- $ sudo apt update
- $ sudo apt install --no-install-recommends yarn
- $ yarn --version
- 1.7.0
Comments
Post a Comment