Lanyon A Simple Blogger template

Free tutorials, courses, generative tools, and projects built with Javascript, PHP, Python, ML, AI,.Net, C#, Microsoft, Youtube, Github Code Download and more.

Install, Update, and Remove Node.js on Ubuntu: A Comprehensive Guide

Node.js is a powerful and popular JavaScript runtime that allows you to build server-side applications and run JavaScript code outside of a web browser. If you're an Ubuntu user and want to harness the capabilities of Node.js for your projects, this guide will walk you through the process of installing, updating, and removing Node.js on your Ubuntu system using various methods.

Install, Update, and Remove Node.js on Ubuntu

Install Node.js on Ubuntu

Method 1: Using the Default Ubuntu Repository

The most straightforward way to install Node.js on Ubuntu is to use the default Ubuntu repository. This method provides a stable version of Node.js, but it may not always be the latest version.

  • Open your terminal by pressing Ctrl + Alt + T.
  • Update the package list to ensure you have the latest information about available packages:

sudo apt update
  • Install Node.js and npm (Node Package Manager) with the following command:
sudo apt install nodejs npm
  • Verify the installation by checking the Node.js and npm versions:
node -v
npm -v

Method 2: Using the NodeSource Repository

If you prefer to install the latest version of Node.js or need a specific version, you can use the NodeSource repository, which provides up-to-date packages.

  • First, install the required dependencies for adding a new repository:
sudo apt install curl software-properties-common
  • Add the NodeSource repository for Node.js:
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg
  • Add the repository to your system:
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/nodesource.list
  • Update the package list again:
sudo apt update
  • Install Node.js and npm from the NodeSource repository:
sudo apt install nodejs npm
  • Verify the installation:
node -v
npm -v

Method 3: Using NVM (Node Version Manager)

NVM is a tool that allows you to manage multiple Node.js versions on your system. It's useful when you need to work with different Node.js versions for different projects.

  • Install NVM by running the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  • Close and reopen your terminal, or run the following command to apply changes without restarting:
source ~/.bashrc
  • To install a specific Node.js version, use NVM. For example, to install Node.js 14, run:
nvm install 14
  • Set the default Node.js version:
nvm use 14
  • Verify the installation:
node -v
npm -v

Update Node.js on Ubuntu

Keeping Node.js up to date is crucial to access the latest features and security updates. Depending on the installation method you chose, here's how you can update Node.js:

Updating from the Default Repository

If you installed Node.js from the default Ubuntu repository, you can update it with the following commands:

sudo apt update
sudo apt upgrade nodejs

Updating from the NodeSource Repository

For Node.js installed from the NodeSource repository, use the following commands:

sudo apt update
sudo apt upgrade nodejs

Updating with NVM

If you used NVM to install Node.js, updating is simple:

  • Update NVM to the latest version:
nvm install --lts
  • Set the newly installed Node.js version as the default:
nvm use --lts
  • Verify the update:
node -v
npm -v

Remove Node.js on Ubuntu

If, for any reason, you need to remove Node.js from your Ubuntu system, you can do so using the following steps:

  • To uninstall Node.js and npm installed from the default Ubuntu repository, run:
sudo apt remove nodejs npm
  • If you installed Node.js from the NodeSource repository, use:
sudo apt remove nodejs npm
  1. If you used NVM to install Node.js, you can uninstall it as follows:

    a. First, deactivate NVM:

    nvm deactivate
    

    b. Then, uninstall NVM:

    rm -rf ~/.nvm
    
  2. Finally, remove any leftover configuration files:

sudo rm -rf /etc/apt/sources.list.d/nodesource.list
sudo rm -f /usr/share/keyrings/nodesource.gpg

Essential Node.js Commands on Ubuntu

Now that you have Node.js installed on your Ubuntu system, let's explore some essential Node.js commands that will help you in your development workflow:

1. Run a JavaScript File

To execute a JavaScript file using Node.js, open your terminal and run:

node filename.js

Replace filename.js with the name of your JavaScript file.

2. Interactive Node.js REPL

Node.js provides an interactive REPL (Read-Eval-Print Loop) environment for experimenting with JavaScript code. Simply type node in your terminal to enter the REPL:

node

You can now enter JavaScript code line by line and see the results immediately.

3. Install Node.js Packages

Node.js uses npm (Node Package Manager) to manage packages. To install a package, use:

npm install package-name

Replace package-name with the name of the package you want to install.

4. Create a New Node.js Project

To create a new Node.js project with a package.json file, navigate to your project folder in the terminal and run:

npm init

Follow the prompts to configure your project.

5. Start a Node.js Server

If you're building a web application, you can start a Node.js server using the http module. Here's a basic example:

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello, Node.js!\n');
});

const port = 3000;
server.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});

Save this code to a file, and run it with node filename.js. Your server will be accessible at http://localhost:3000/.

6. Install Global Packages

To install a package globally (available system-wide), use the -g flag:

npm install -g package-name

Global packages are often command

-line tools or utilities that you want to use across different projects.

In this comprehensive guide, we've covered multiple methods for installing Node.js on Ubuntu, updating it to the latest version, and safely removing it from your system if needed. We've also introduced you to some essential Node.js commands that will be valuable in your development journey.

Whether you're a seasoned developer or just getting started with Node.js, having a well-maintained Node.js environment on your Ubuntu machine is essential for building robust and efficient server-side applications. So, go ahead and install Node.js, explore its capabilities, and start creating amazing projects on your Ubuntu system with confidence.

Share this post

Popular posts from this blog

Bing Homepage Quiz: Fun, Win Rewards, and Brain Teasers

CVR Nummer : Register CVR Number for Denmark Generate and Test Online

How To Iterate Dictionary Object

Search This Blog

What's New

How to build your own learning path using Open Source with Kunal Kushwaha [Podcast #200]

Image
Curriculum for the course How to build your own learning path using Open Source with Kunal Kushwaha [Podcast #200] Today Quincy Larson interviews Kunal Kushwaha. He's a software engineer and prolific computer science teacher on YouTube. He failed the JEE, the Indian Engineering Entrance Exam, TWICE. But he persevered. He did 4 years of university but attended ZERO lectures. Instead he built his own learning path by contributed to open source projects and using free learning resources including freeCodeCamp. He moved from Delhi to London on a UK Global Talent Visa. He works at Cast AI and is the founder of the WeMakeDevs community. We'll talk about: - How he teaches himself new skills, then teaches those skills through his YouTube channel - His day-to-day working remotely at startups - His role in building out cloud regions as a field CTO at Civo, a cloud native service provider - The Indian higher education system Support for this podcast is provided by a grant from Algo...

Labels

Programming Video Tutorials Coursera Video Tutorials Plurasight Programming Tutorials Udemy Tutorial C# Microsoft .Net Dot Net Udemy Tutorial, Plurasight Programming Tutorials, Coursera Video Tutorials, Programming Video Tutorials Asp.Net Core Asp.Net Programming AWS Azure GCP How To WordPress Migration C sharp AWS Project Git Commands FREE AWS Tutorial OldNewThings Git Tutorial Azure vs AWS vs GCP New in .Net javascript AI Google I/O 2025 Wordpress jquery Generative Video Git Git Squash Google Flow AI PHP SQL Veo 3 squash commit CSS Cloud Services React Tutorial With Live Project Source Code git rebase CPR Nummer Dropdown Reset Javascript Figma Figma Beginner Tutorial Geolocation Non-Programmer Content Python Free Course Think Simply Awesome Tutorial UI UX Live Project UI/UX Full Course Wireframing dotnet core runtime error html API Gateway AWS EKS vs Azure AKS All in one WP stuck C++ C++ Coroutines CPR Denmark ChatGPT Cloud Database Cloud DevOps Cloud Security Cloud Storage Contact Form 7 Dropdown Unselect Javascript E commerce Free AWS Terraform Project Training Git Commit Google Drive Files Google Drive Tips Http Error 500.30 Http Error 500.31 Interview Questions Learn Courutines C++ Microservices for Live Streaming PII Denmark Pub Sub SQL Server SSIS Terraform Course Free Terraform Tutorial Free USA E commerce strategies UpdraftPlus UpdraftPlus Manual Restore Website Optimization Strategies dropdown javascript select drop down javascript smarttube apk error 403 smarttube next 403 Error 413 Error 503 504 524 AI & ML AI Assistants AI Course CS50 AI in daily life AWS API Gateway AWS EBS AWS EC2 vs Azure VMs vs GCP Compute Engine AWS EFS AWS IAM AWS Lamda AWS RDS vs Azure SQL AWS Redshift AWS S3 AZ-104 AZ-104 Free Course AZ-104 Full Course AZ-104 Pass the exam Abstract Class C# Abstract Method Ajax Calender Control Ajax Control Toolkit All In One Extension Compatibility All In One WP Freeze All In One WP Migration All in one WP All-in-One WP Migration Android 15 Android TV Applying Theme html Asp.net core runtime Error Audio Auto Complete Azure AD Azure APIM Azure Administrator Certification Azure Blob Storage Azure Data Lake Azure Files Azure Function Azure Managed Disk Azure Synapse Base Class Child Class Best Grocery Price Big Data BigBasket vs Grofers Bing Homepage Quiz Blogger Import Blogger Post Import Blogger XML Import Bluetooth Connectivity Browser Detail Building Real-Time Web Applications Bulk Insert CI/CD CPR Address Update CPR Generator CPR Generator Denmark CS50 AI Course CS50 AI Python Course CS50 Artificial Intelligence Full Course CVR Centrale Virksomhedsregister Change Workspace TFS ChatGPT Essay Guide ChatGPT Usage ChatGPT vs Humans Cloud API Management Cloud CDN Cloud Computing Cloud Data Warehouse Cloud Event Streaming Cloud IAM Cloud Messaging Queue Cloud Monitoring and Logging Cloud Networking CloudFront Cloudflare Cloudwatch Compute Services Connect a Bluetooth Device to my PC site:microsoft.com Containers ControlService FAILED 1062 Corona Lockdown MP CosmosDB Covid19 Covid19 Bhopal Covid19 Home Delivery MP Covid19 Indore Covid19 Susner Covid19 Ujjain Cypress Javascript Cypress Javascript framework Cypress Javascript testing Cypress Javascript tutorial Cypress Javascript vs typescript DNS Danish CVR Data Analytics Data Analytics Course Free Data Engineering Data Structure Full Course Data Visualization Database Database Diagram Visualizer Davek Na Dodano Vrednost Dbdiagram export seeder Deep Learning Course Denmark Numbers Det Centrale Personregister Det Centrale Virksomhedsregister DevOps Device Compatibility Dictionary Dictionary in C# Digital Economy Disaster Recovery for Web Applications Disaster-Proof Infrastructure Dmart Frenchise Dmart Home Delibery Dmart Mumbai Address Dmart Pickup Points Doodle Jump Drive Images On Blog Drive Images On Website Driver Problems DropDown Dropbox Dropdown jquery DynamoDB ETL ETL Package Ecommerce Store using AWS & React Embed Drive Images Escape Sequences in c#.Net Event Hub Explicit Join Extract Facebook App Fake CVR Denmark Fake DDV Slovenia Fake VAT Number Fake Virk Number Faker Feature Toggle Find CPR Information Find a Word on Website Firestore Flappy Bird Game Form Selectors using jQuery Free React Portfolio Template FreeCodeCamp Frontend Best Practices for Millions of Users Full Text Index View G Drive Hosting GAN certification course GCP Cloud Data Lake GCP Filestore GCP Functions GCP IAM GCP Persistent Disk Gemini Git Checkout Google Adsense Setting Google Beam Google BigQuery Google Conversion Tracking Google Docs Advanced Tutorial Google Drive Clone Google Drive Clone Bot Google Drive Clone HTML CSS Google Drive Clone PHP Google Drive Clone React Google Drive Clone Tutorial Google Drive Clone VueJS Google Drive File Sharing Google Drive Images Google Drive Sharing Permissions Grocery Price Compare Online Grocery in Corona Grocery in Covid19 Grofers vs DMart vs Big basket HAXM installation HTML Storage HTML to PDF Javascript HTML2Canvas HTML5 HTML5 Append Data HTML5 Audio HTML5 Data Storage HTML5 Storage HTML5 Video Harvard University AI Course Header Sent Height Jquery High Availability in Live Streaming Platforms High-Concurrency Frontend Design High-Concurrency Web Applications How to Search for a Word on Mac Html2Canvas Black Background issue Http Error 413 Http Error 500.35 IIS INNER Join Image Gallery Blogger Image Gallery Blogger Picasa Image Gallery Blogger Template Image Gallery Blogger Template Free Implicit Join Indexing in SQL Instagram Clone React Instagram Clone Script Install NodeJS Ubuntu Internet Infrastructure Interview IoT IoT Core IoT Hub JS Game Tutorial Java Feature Toggle Javascript game tutorial JioCinema Case Study Keep Me Login Key Management Kinesis Learn Scrappy with a live project List Live Streaming Data Delivery Live Streaming Performance Optimization Load Load Balancer Looping Dictionary MTech First Semester Syllabus MTech Syllabus MVC Mac Mac Finder Shortcut Media Controller Media Group Attribute Microservices Architecture for Scalability Missing MySQL Extension Mobile Optimization Multiple Audio Sync Multiple Video Sync Mumbai Dmart List MySQL MySQL ERD Generator Next.js Beginner Tutorial Ngnix NodeJS NodeJS Ubuntu Commands Numpy OOPS Concepts OOPS in C# Object Oriented Programming Object Storage Outer Join PHP Installation Error PHP WordPress Installation Error Pandas Personligt identifikations nummer Pipedrive Pipedrive Quickbooks Integration Portfolio Website using React Project Astra PyTorch Quickbooks Quote Generator RGPV Syllabus Download Random SSN Generator ReCaptcha Dumbass React Feature Toggle Real-Time Video Processing Architecture Real-Time Video Processing Backend RegExp Regular Expression Reinstall Bluetooth Drivers Remember Me Remove NodeJS Ubuntu Renew DHCP Lease Reset IP Address Linux Reset IP Address Mac Reset IP Address Windows Reset Remote Connection Reset Remote Connection Failure Resize Textarea Restore Errors Restore Failed UpdraftPlus Route 53 SOS Phone SQL Indexed Tables SQL Joins SQL Seed generator SQS SSIS Package SSIS Tutorial SSN Generator for Paypal SSN Number SSN Number Generator SSN Validator Safari 8 Safari Video Delay SageMaker Scalable Backend for High Concurrency Scalable Cloud Infrastructure for Live Streaming Scalable Frontend Architectures Scalable Live Streaming Architecture Scrapy course for beginners Search A word Search for a Word in Google Docs Secret Management Serverless Service Bus Slovenian VAT Generator SmartTube Software Architect Interview Questions Software Architect Mock Interview Sparse Checkout Spotlight Mac Shortcut Stored Procedure Subtree Merge T-Mobile IMEI Check TFS TMobile IMEI check unlock Team Foundation Server Terraform Associate Certification Training Free Text Search Text color Textarea Resize Jquery Theme Top WordPress Plugins Transform Trim javascript Troubleshooting TypeScript Beginner Tutorial Ubuntu Unleash Feature Toggle Update Computer Name UpdraftPlus 500 UpdraftPlus Backup Restore UpdraftPlus Error 500 UpdraftPlus Error 504 UpdraftPlus Error 524 UpdraftPlus HTTP Error UpdraftPlus New Domain UpdraftPlus Restore Not Working UpdraftPlus Troubleshooting Upstream Reset Error Use Google Drive Images VAT Number Generator Verizon imei check Verizon imei check paid off Verizon imei check unlock Verizon imei check\ Version Control Vertex AI Video View Indexing SQL Views in SQL Virksomhedsregister Virtual friends Visual Studio 2013 WHERE Clause WHPX expo Web Security Web scraping full course with project Web3 What is Feature Toggle WordPress Backup Troubleshooting WordPress Backup UpdraftPlus WordPress Database Backup WordPress Error 503 WordPress Installation Error WordPress Migration UpdraftPlus Wordpress Restore Workspaces Commands Your ip has been banned Zero Click angle between two points bing homepage quiz answers bing homepage quiz answers today bing homepage quiz not working bing homepage quiz reddit bing homepage quiz today byod Verizon imei check chatgpt essay example chatgpt essay writer chatgpt essay writing check tmobile imei contact form 7 captcha contact form 7 captcha plugin contact form 7 recaptcha v3 cpr-nummer engelsk cpr-nummer liste cpr-nummer register cpr-nummer tjek dbdiagram dom load in javascript dotnet core hosting bundle dotnet failed to load dotnet runtime error get url in php how to search for a word on a page how to search for a word on a page windows ipconfig release is cypress javascript istio transport failure jQuery AutoComplete jQuery Input Selector jQuery Menu jQuery Options joins in mySql jquery selector jquery selectors jsPDF jsPDF images missing key key-value keypress event in jQuery kubernetes upstream error localStorage metro by t-mobile imei check nemid cpr-nummer react native expo setup react native on Windows react native setup recaptcha v3 contact form 7 recaptcha wordpress contact form 7 reset connection failure resize control jQuery response code 403 smarttube round number in javascript select sessionStorage smarttube 403 エラー smarttube apk smarttube beta smarttube download smarttube reddit smarttube unknown source error 403 smartube sos iphone top right sos on iphone 13 sos only iphone substr substr in javascript tmobile imei tmobile imei check paid off tmobile imei number total by Verizon imei check trim trim jquery turn off sos iphone turn off sos on iphone 11 unknown source error 403 unknown source error response code 403 smarttube upstream connect error url in php view hidden files mac finder zuegQmMdy8M ошибка 403 smarttube
  • ()
  • ()
Show more
an "open and free" initiative. Powered by Blogger.