Menu
Node.js is required for using many JavaScript tools and for creating server-side JavaScript applications. Here is how you install Node.js on a Mac.
- Upgrade Node On Mac
- Download Node Js On Mac
- Node Js Download Mac Download
- Git Download
- Node Js Download Mac Installer
The first thing you should do is check to see if you have a version of Node.js already installed. To do that:
- Open the Terminal by pressing Command+Space to open Spotlight Search and entering
Terminal
then pressing Enter. - Enter
node - v
in the Terminal and press Enter. - If you do have Node.js installed, it will output the version.
- Update to the latest version using
npm i -g npm
. If you get a bunch ofcheckPermissions
warnings, you should run the command as the superuser like this:sudo npm i -g npm
- You now have the latest version installed. You do not need to continue with these instructions.
- Update to the latest version using
- If you do not have Node.js installed, it will output something like
-bash: node: command not found
. Continue with these instructions to install it. - Go to nodejs.org. You'll see download links for MacOS. If you are using Node.js for a Webucator class, you should select the LTS version. The Current version has the latest features, but may be more prone to changes and bugs than the LTS (Long Term Support) version.
- When the file finishes downloading, locate it in Finder and double-click on it.
- Go through the entire installation process.
- When installation is complete, open the Terminal by pressing Command+Space to open Spotlight Search and entering
Terminal
then pressing Enter. - Enter
node - v
in the Terminal to verify that Node.js is installed correctly and to see the version of Node.js that was installed.
- Last updated Saturday, Nov 16, 2019 Setting up Node.js and npm on Mac OSX Node.js is gaining a lot of speed and is an exciting new development framework. Here's a quick overview of how to get Node.js working on OSX along with npm, the package manager for node.
- Click on macOS Installer to download the latest version of node installable package. 2.Install nodejs Click on the download node-vxx.xx.xx.pkg (for example node-v10.15.0.pkg) in previous step to start the installation which brings up below screen.
- Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Latest Current Version: 15.0.1 (includes npm 7.0.3) Download the Node.js source code or a pre-built installer for your platform, and start developing today.
Installation on a Mac or Linux. In order to install everything on a Mac, we'll be running commands in Terminal.app, and Linux distributions vary. Install Node.js and npm. We’re going to use Node Version Manager (nvm) to install Node.js and npm.
Upgrade Node On Mac
If a version was output, then you're all set.
Introduction
Node.js is a run-time environment used for executing JavaScript outside the browser. Npm is a JavaScript package manager commonly used for installing packages for Node.js.
In this article, you will learn how to install Node.js and npm on Mac or Linux. You will also learn how to verify the installation, run Node.js code, and how to update Node.js and npm.
When you’re finished, you’ll be able to run Node.js code on Mac or Linux computer.
Prerequisites
To follow this tutorial successfully, you’ll need the following:
![Download Download](/uploads/1/1/8/6/118685058/286791195.png)
Download Node Js On Mac
- Internet access to download Node.js.
- Basic knowledge of how to use the terminal.
Step 1 — Install Node.js and npm on Mac or Linux
There are a couple of ways to install Node.js on Mac or Linux. The most recommended method and also my favorite method to install Node.js and npm is to use Node Version Manager(nvm).
Using nvm has the following benefits:
- It allows you to install multiple versions of Node.js.
- It makes it easy to switch between the versions.
- Updating node.js is a breeze with nvm.
![Node Js Download Mac Node Js Download Mac](/uploads/1/1/8/6/118685058/601116292.png)
So let’s now install nvm. Copy and paste the command below into your terminal.
Info: If your on Mac, open your
~/.bash_profile
or create a new one if the ~/.bash_profile
file does not exist. Make sure you add source ~/.bashrc
in the file and save.Now let’s verify if
nvm
was installed successfully.Your terminal should display the current version of nvm. At the time of writing, the current version is 0.35.2. So this is the output I got.
Note: On Linux, if you get
nvm: command not found
or no feedback, close your terminal and open a new terminal and enter the nvm --version
again. If you using ssh to access linux, you might need to restart your session.Tip: On Mac, if you are having any issues with the
nvm
command not working, check out this linkLets now install Node using nvm’s install command.
Once installed, set the installed version as the default.
Info: You need to set the default version because nvm forgets the node version in a new terminal session. You can learn more about the issue here.
Step 2 — Verify Node.js and npm installation
Verify if Node.js and npm were successfully installed.
Type
node -v
. It will display the current Node.js version.Type
npm -v
to display the current npm version.Your output should look similar to mine. Note that the versions will be different since you might be reading this tutorial when new versions came out.
Running Node.js Code on Mac or Linux
There are two ways to run Node.Js code:
- Node.js REPL
- Running Node.js scripts on the terminal
Node.js REPL
REPL stands for Read-Evaluate-Print-Loops. It is an interactive shell that allows experimentation of JavaScript code. It works the same way as the web browser console.
To access the Node REPL, type
node
in the terminal.The REPL prompt will be opened where you can enter the JavaScript code.
The
>
sign is there to let you know that the code entered will be immediately evaluated when you press enter.To exit out of the REPL, type
.exit
or press CTRL+D
once. You can also exit out by pressing CTRL+C
twice.Running Node.js Scripts on the Terminal
This method is the one that is commonly used to run Node. You will write Node.js code in a file with an extension of
.js
and run it in the terminal using the node
command.Let’s see this in action by creating a directory named
node.js
in our home directory.mkdir
is a command used for creating directoriesLet’s go into the
nodejs
directory.Node Js Download Mac Download
Your terminal should now show you are in the
node.js
directory.Git Download
Create a file
first-program.js
. For simplicity’s sake, we will use Nano which is a terminal text editor.Enter the following code in
first-program.js
in the Nano editor.Hold CTRL+O and then press
enter
to save the file.Exit out of the editor by holding
CTRL+X
.Node Js Download Mac Installer
Let’s now run the code in
first-program.js
:Your output should look like below.
I hope you have understood how to run Node.js code on your Mac or Linux system.
Next, we are going to learn how to update Node.js and npm using nvm.
How to Update Node.js and npm using nvm
To update to the latest version Node.js and npm. Type the following:
To update to the latest LTS(Long Term Support) version. Type the following:
Conclusion
In this article, you learned how to install and update Node.js and npm on Mac or Linux. We also looked at different ways on how to run Node.js code. I hope you are now confident to run Node.js scripts on your computer on your Mac or Linux computer.
If you have any insights or suggestions, feel free to leave a comment. I would love to hear from you.