Latest Guide to Install npm and node js in Mac OS

Just like other JavaScript frameworks React Native also requires npm to manage the dependency so here is the Latest Guide to Install npm and node js in Mac OS.

For those who are new in the Javascript framework world

npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry.

We can say that npm is a package manager for Node.js with hundreds of thousands of packages.

Although it does create some of your directory structure/organization, this is not the main purpose. The main goal, as you touched upon, is the automated dependency and package management.

Whenever you work with npm/node you can see it manages a file called package.json in which it stores all the dependency you have used in your project under the dependency section. Which means you can specify your project’s dependencies in the package.json file and any time you or anyone else needs to get started with your project they can just need to run npm install which will install all the dependencies in the node_module directory. On top of this, it is also possible to specify what versions your project depends upon to prevent updates from breaking your project.

In this example, we will show you how to install npm and node js in Mac OS, If you have a Linux or Windows machine then please visit Latest Guide to Install npm and node js for Ubuntu and Windows.

Prerequisites

Before you can install Node, you’ll need to install two other applications. Fortunately, once you’ve got these on your machine, installing Node takes just a few minutes.

  1. XCode. Apple’s XCode development software is used to build Mac and iOS apps, but it also includes the tools you need to compile software for use on your Mac. XCode is free and you can find it in the Apple App Store.
  2. Homebrew. Homebrew is a package manager for the Mac — it makes installing most open source sofware (like Node) as simple as writing
    brew install node

    You can learn more about Homebrew at the Homebrew website. To install Homebrew just open Terminal and type

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    You’ll see messages in the Terminal explaining what you need to do to complete the installation process.

Install npm and node js in Mac OS

1. First of all, you need to check whether Homebrew is installed in your Mac or not? To check this run

brew -v

If you already have Homebrew installed it will show you the installed version of Homebrew

else will show brew: command not found

2. If you have Homebrew installed then you can skip this step else install Homebrew using

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

3. Now after installing brew you can run the following command to install node and npm in your Mac. This will completely install node into your Mac.

brew install node

4. After installation of node. You can check using

node -v
npm -v

This will show the installed version of node and npm in your Mac.

5. Now install watchman (It is a tool by Facebook for watching changes in the filesystem)

brew install watchman

6. Install JDK (If you already have JDK installed in your system then you can skip this step, make sure it is JDK 8 or newer.)

brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8

7. Install React Native CLI: Node comes with npm, which will help you to install this using

npm install -g react-native-cli

How to Update Node and NPM

New versions of node and npm come out frequently. You can use Homebrew to update the software it installs.
1. Make sure Homebrew has the latest version of the Node package

brew update

2. Upgrade Node

brew upgrade node

How to Uninstall Node and NPM

You can use Homebrew to uninstall packages

brew uninstall node

This was the best way to install the nodejs and npm in Mac OS. If you are facing any problem or if you have any doubt about the topic you can comment below or contact us here.

Hope you liked it 🙂

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.