Skip to content

Instantly share code, notes, and snippets.

@netsensei
Last active June 8, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netsensei/c1d28bdbbfb9b0bfa2feecb6f396b911 to your computer and use it in GitHub Desktop.
Save netsensei/c1d28bdbbfb9b0bfa2feecb6f396b911 to your computer and use it in GitHub Desktop.
Setting up NodeJS with NVM on Centos 7

Setting Up NodeJS with NVM on Centos 7

Centos 7 offers NodeJS and NPM via yum install. While this is great, it's not optimal because it pins users to the version offered via yum. Moreover, a yum update can easily upgrade the NodeJS version leading to all kinds of breaking. Not what we want.

Luckily, nvm can help us.

In the same vain as rbenv, rvm or plenv: this is a version manager that leaves the "system" node installation alone and allows you to install and manage different versions of nodejs and npm concurrently.

Installation

Go to https://github.com/nvm-sh/nvm for the instructions.

Run this command to install nvm locally (warning: don't run this as root)

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
$ source .bashrc

NodeJS

NodeJS has a panoply of versions. Easiest is to install the latest LTS (long term support) version. Why? Because once you start installing node modules via npm you want to ensure compatibility with your currently installed LTS version of NodeJS.

Consider that moving between LTS versions would be similar to moving between major versions of other languages (perl, ruby, python,...) causing breaking API changes.

Let's install the latest LTS version

$ nvm install --lts
$ node --version
v12.18.0
$ npm --version
6.14.4

Installing Yarn next to NPM

Starting a project

Starting a project starts with npm init. Without any extra arguments, it just creates a package.json file. But you could add a loader which will then create an entire directory structure depending on the type of project you want to work on: react, angular, etc.

Adding WebPack

Webpack manages the build pipelines of your project. Be it compiling SCSS files, transpiling ES code or building a React application.

$ npm install --save-dev webpack webpack-cli

see: https://webpack.js.org/guides/installation/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment