Install Node.js using nvm with Node.js and V8 compiled optimized for your CPU

If you install Node.js using nvm as a binary package such as using:

nvm install <node_version>

You’ll get a usable Node.js. However, this Node.js isn’t optimized specifically for your CPU architecture. To install Node.js specifically for your CPU architecture, we can make use of -march=native provided by mainstream C/C++ compilers. To do this, use the following command to install Node.js instead:

CFLAGS='-march=native' CXXFLAGS='-march=native' nvm install -s <node_version>