Hey there and welcome to Learn WordPress.
In this tutorial you're going to learn how to install Node.js and npm on your computer for local WordPress development.
You will learn why you should install this software,
what the requirements are,
and how to install Node.js and npm on your computer.
Node.js is a JavaScript runtime environment that allows you to run JavaScript code outside of a web browser.
While this might not be specifically applicable to developing with WordPress, Node.js also comes bundled with npm.
npm is both a command line tool and a package manager for JavaScript.
It allows you to install and manage JavaScript packages, also known as dependencies, as well
as run build tools, execute code linters, and automate many other processes during development.
Many WordPress development projects rely on npm, including Gutenberg, the Create Block
tool, the wp-env local WordPress environment, and the new wp-now local WordPress environment.
In order to run Node.js and npm, you're going to need access to a terminal to run commands.
Depending on your operating system, you might already have an existing terminal installed.
macOS and/or any Linux users can use the terminal that ships with the operating system.
If you are a Windows user and you don't already have a terminal solution,
we recommend installing and using PowerShell as it's more beginner-friendly
and more tailored to the Windows operating system. To install PowerShell, either open the
Microsoft Store and search for PowerShell or browse to microsoft.com/powershell. Browse to
Set up and Installation and then follow the instructions to download and install it.
Because npm is bundled with Node.js you just need to install Node.js to get up and running.
While you can browse to the Node.js website, download the installer and install it that way,
we recommend using a tool called nvm which stands for Node Version Manager.
You can find nvm at github.com/nvm-sh.
This tool will enable you to install
and use different versions of Node.js,
depending on the requirements
of the software you're working with.
If you're using macOS or Linux,
you can open your default terminal application
and install nvm by running the nvm install script,
which you can copy from the installing
an updating section of the nvm README file.
Once it is installed, you can use the nvm install command to install the Node.js and npm versions you need.
Here on a Windows machine, you will need to install the Chocolaty Package Manager for Windows to install NVM.
First, open PowerShell with administrator privileges by right-clicking on the PowerShell menu item and selecting "Run as administrator".
Then, browse to the Chocolaty setup documentation and scroll down to the Install with PowerShell
instructions.
Copy the instructions and right-click in the PowerShell window to paste them.
Once Chocolaty is installed, use the following command to install nvm.
Choco install -y nvm
Once nvm is installed, use the nvm install command to install the required Node.js and
npm versions.
To install Node.js and npm, use the nvm install command with the version number you want to
install.
At the time of this tutorial, the current stable version of Node.js is version 18.
So you would say nvm install 18.
You can also run nvm list to see which versions of Node.js are installed.
Because nvm allows you to run multiple versions of Node.js, you need to tell nvm which version
you want to use.
You can do this by running the nvm use command followed by the version number.
You can also set the default version of Node.js and npm
by using the nvm alias command.
And then to check which versions of Node.js and npm
are enabled by running the following commands,
node -v and npm -v.
And that wraps up this tutorial on installing Node.js and npm.
Happy coding!