We can install Node.js a few different ways. Either approach should suffice for this class.
The first approach to install Node.js is from the Node.js site with a GUI installer. Choose the Long Term Support (LTS) version, which is the green button on the left.
The only issue you may run into (Mac users in particular) when installing Node.js this way is when you install Node.js modules globally. For example, if you run
npm install -g create-react-app, you may get an error saying something along the lines of not having sufficient privileges. In order to get around this, you can prefix that command with
sudo npm install -g create-react-app). Another issue with installing Node.js like this is if you have multiple projects that use different Node.js versions. We will use a single version of Node.js for everything we do in this class.
A more popular approach to installing Node.js is through Node Version Manager (NVM) for Mac or Node.js version manager for Windows. NVM allows you to have multiple versions of Node.js installed on your computer at once. You also don’t run into the problem of having to use
sudo when installing modules globally.
Unfortunately I don’t have a Windows machine nor have I used NVM on Windows before. I did however see lots of tutorials on YouTube. If you’re on a Mac and wish to install Node.js via NVM, follow these instructions:
- Follow the instructions under “Install & Update Script”: https://github.com/nvm-sh/nvm#install—update-script.
- Restart Terminal
nvmand press Enter. You should see a list of options.
- To install version 14.17.0 of Node.js, run
nvm install v14.17.0. Replace “v14.17.0” with any recent version. Anything above version 12.x.x should suffice for this course. Once that finishes, run
nvm lsto list out all the versions of Node.js that you have installed. If you would like to set a specific version of Node.js as the default, run
nvm alias default <version>(i.e.
nvm alias default v14.17.0).
To verify you have Node.js installed, open up your command line and run
node -v. You should see the version of Node.js that you installed.