My Logo

PUBLISHED JANUARY 08, 2024

Teghen Donald Ticha
Lastly Updated: 3 months ago
Reading time 22 mins

How to Install and Setup NodeJS

In this series part, I run you through the various ways to install nodeJS. I also discuss how to install nvm and use it to switch between different node versions.
How to Install and Setup NodeJS

Prerequisite

No prior knowledge is required for this series part.

You may start with for a smoother follow up of the tutorial series, but it’s not required.

Step 1 : Install Node.js
  1. 1.Visit the nodejs official website at nodejs.org (https://nodejs.org/)
  2. 2.You will be presented with two buttons one for the LTS(Long Term Support)version and the other for the current version.

    Clicking on either will launch a download of nodeJS source code or a pre-built installer for your platform (Windows, macOS, or Linux).

    For beginners, the LTS (Long Term Support) version is recommended. However, if you wish to select a specific platform yourself, you can visit the download page here or by clicking the download button in the website’s header nav.

    Once you’re there, you can choose whichever option suits your use case.
  3. 3.Once the download is complete, run the installer and follow the on-screen instructions.
Step 2: Verify the installation

Open your terminal or command prompt and type the following command to check if Node.js is installed:

node -v


As npm (Node Package Manager) comes bundled with Node.js, you don't need to install it separately.
After node installation is complete, npm is also installed automatically. To check the npm version, use the following command in your terminal:

npm -v

If both commands return version numbers, congratulations! Node.js is successfully installed.

You can also find the path to the node installation with this command;

which node


In my case produces the following :

Command-line Output

You should get something similar, but most probably you will get different version numbers.

One very convenient way to install NodeJS is through a package manager. However in this case, each OS has its set of package managers. You can find some very popular ones for windows, Linux and macOS via this link https://nodejs.org/download/package-manager/


Here we are going to focus on a very popular, straightforward and easy to use package manager, NVM(Node Version Manager).

NVM is a POSIX-compliant bash script to manage multiple active nodeJS versions ie;

It allows you to quickly install and use different versions of node directly from terminal.

Installing and Updating NVM

To install or update nvm, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash


or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

You may find more info or debug guidelines on their GitHub page, should you run into any issues while installing or updating your nvm package.

For a beginner, I personally argue that the most convenient way to install and manage nvm and many other dev tools is by using the popular package manager, `Homebrew`.

I know what you are thinking at this point.

What the heck, another installation 🤔? Trust me, it's much easier this way. Just, bare with me😅.

What does it do anyhow? Well, it installs the stuff you need that your mac (or your Linux system) didn’t have, effortlessly.

NB: `this section is for macOS and Linux users only.`

Installing Homebrew is straightforward. Run this commend below in a new terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


Once Homebrew is successfully installed, all that is left is to run the following command in your terminal;

brew install nvm

That’s it, told you! Pretty cool huh😎?

Now you may start playing around with different versions of nodeJS as needed. Here are a few commands you can try. Have fun!

$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
v16.9.1
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
v14.18.0
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v
v12.22.6


In this series part, we focused on installing and setting up nodeJS for basic and generic use.

In the next part, we will discuss about how much JS (JavaScript) / TS (TypeScript) does one need to learn nodeJS

All Chapter Parts for NodeJs In Theory, An absolute Beginner’s Overview
  1. Chapter 1 , Part 1 : Introduction to NodeJS

    In this series part, I introduce nodeJS and some technical concepts associated with it. I also show how easy it is to setup and start a simple nodeJS web server.

  2. Chapter 1 , Part 2 : How to Install and Setup NodeJS

    In this series part, I run you through the various ways to install nodeJS. I also discuss how to install nvm and use it to switch between different node versions.

  3. Chapter 1 , Part 3 : How much JavaScript do you need to learn NodeJS

    In this series part, we explore the nuanced relationship between JavaScript and NodeJS, highlighting some subtle distinctions between the two environments.

  4. Chapter 1 , Part 4 : The v8 Engine and the difference Between NodeJS and the browser

    In this series part, we explore the V8 engine and how it interacts with nodeJS. We also discuss node’s event loop and uncover the mystery behinds node’s ability to handle concurrent operations.

  5. Chapter 1 , Part 5 : NPM, the NodeJS package manager

    Discover the essentials of npm, the powerful package manager for Node.js. Learn installation, management, publishing, and best practices

  6. Chapter 1 , Part 6 : NodeJS in Development Vs Production

    Explore how Node.js behaves differently in development and production environments. Learn key considerations for deploying Node.js applications effectively.

  7. Chapter 2 , Part 1 : Asynchronous Flow Control

    In this series part, we'll explore various aspects of asynchronous flow control in Node.js, from basic concepts to advanced techniques.

  8. Chapter 2 , Part 2 : Blocking vs Non-blocking I/O

    Explore the differences between blocking and non-blocking I/O in Node.js, and learn how to optimize performance and scalability.

  9. Chapter 2 , Part 3 : Understanding NodeJS Event loop

    Exploring the Node.js event loop by understanding its phases, kernel integration, and processes enabling seamless handling of asynchronous operations in your applications.

  10. Chapter 2 , Part 4 : The NodeJS EventEmitter

    Explore the power of Node.js EventEmitter: an essential tool for building scalable and event-driven applications. Learn how to utilize it effectively!

  11. Chapter 3 , Part 1 : Working with files in NodeJS

    Gain comprehensive insights into file management in Node.js, covering file stats, paths, and descriptors, to streamline and enhance file operations in your applications.

  12. Chapter 3 , Part 2 : Reading and Writing Files in NodeJS

    Uncover the fundamentals of reading and writing files in nodeJS with comprehensive examples and use cases for some widely used methods.

  13. Chapter 3 , Part 3 : Working with Folders in NodeJS

    Unlock the secrets of folder manipulation in Node.js! Explore essential techniques and methods for working with directories efficiently

  14. Chapter 4 , Part 1 : Running NodeJS Scripts

    Master the command line interface for executing nodeJS scripts efficiently. Learn common options and best practices for seamless script execution

  15. Chapter 4 , Part 2 : Reading Environment Variables in NodeJS

    Learn how to efficiently manage environment variables in nodeJS applications. Explore various methods and best practices for security and portability

  16. Chapter 4 , Part 3 : Writing Outputs to the Command Line in NodeJS

    Learn essential techniques for writing outputs in nodeJS CLI. From basic logging to formatting and understanding stdout/stderr.

  17. Chapter 4 , Part 4 : Reading Inputs from the Command Line in NodeJS

    Learn the various ways and strategies to efficiently read command line inputs in nodeJS, making your program more interactive and flexible.

  18. Chapter 4 , Part 5 : The NodeJS Read, Evaluate, Print, and Loop (REPL)

    Explore the power of nodeJS's Read, Evaluate, Print, and Loop (REPL). Learn how to use this interactive environment for rapid prototyping, debugging, and experimentation.

  19. Chapter 5 , Part 1 : Introduction to Testing in NodeJS

    Discover the fundamentals of testing in nodeJS! Learn about testing types, frameworks, and best practices for building reliable applications.

  20. Chapter 5 , Part 2 : Debugging Tools and Techniques in NodeJS

    Explore essential debugging tools and techniques in Node.js development. From built-in options to advanced strategies, and best practices for effective debugging.

  21. Chapter 6 , Part 1 : Project Planning and Setup

    Discuss the planning and design process for building our interactive file explorer in Node.js, focusing on core features, UI/UX design, and implementation approach and initial setup.

  22. Chapter 6 , Part 2 : Implementing Basic functionalities

    In this guide, we'll implement the basic functionalities of our app which will cover initial welcome and action prompts.

  23. Chapter 6 , Part 3 : Implementating Core Features and Conclusion

    In this guide, we'll complete the rest of the more advanced functionalities of our app including, create, search, sort, delete, rename and navigate file directories.