Homebrew is a package manager for macOS that simplifies the installation and management of software and development tools. It allows you to easily install, update, and uninstall software packages, making it an invaluable tool for developers. Make sure you have administrator access and follow the below steps to install Homebrew on your Mac.
- Open Terminal app on your Mac by going to “Applications > Utilities” folder or using Spotlight Search by pressing “Command + Space” keys.
- To install Homebrew, paste the following command in the prompt and press enter. This command will initiate the Homebrew installation process:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- During the installation, Homebrew will provide prompts and instructions and you will be prompted to type administrator password. Press “Enter” key when prompted to continue the installation.
- After the installation is completed, you will be prompted to run two commands as next steps to add it to your shell’s PATH. These commands will make Homebrew readily accessible from your Terminal. Below are the syntaxes for those commands (make sure to change your user name) or copy them directly from your Terminal.
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/<user_name>/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"
- Execute those commands one by one.
- Now that, you have set the PATH of Homebrew, the setup has been completed. You can verify it by running the following command in the Terminal app and you should see the Homebrew version displayed.
- Once brew has been installed on your Mac, update it to ensure you have the latest package information. Type the below command in the prompt and press enter.
Installing NPM and Node.JS
Open Terminal app and simply run the following command. Once you execute this command, Homebrew will download and install the latest versions of Node.js and NPM. This might take few moments to finish.
brew install node
Note that if you wish to install a particular Node.js version, such as version 14, you can achieve this by executing the following command:
brew install node@14
Now, to verify that Node.js and NPM were installed successfully and to check their versions, use these commands:
node -vto check the Node.js version.
npm -vto check the NPM version.
Uninstalling NPM and Node.js
If you ever need to uninstall Node.js and NPM, you can do so using Homebrew’s uninstall command. Simply type the below command in the Terminal and press enter.
brew uninstall node
To ensure Node.js and NPM are completely uninstalled from your system, you can also run these optional commands to remove any leftover configuration files:
rm -rf /usr/local/lib/node_modules rm -rf /usr/local/include/node rm -rf /usr/local/include/node_modules
To confirm that Node.js and NPM have been successfully uninstalled, run the same version checking commands again.
node -v should return “module”No such file or directory” error.
npm -v will show module not found errors.