Installing/Using NodeJS

MageStack natively supports NodeJS and provides an installer for Node Version Manager (NVM) to enable you to easily install and switch between NodeJS versions.

! The following should be run as the www-data user

Installation

Installation is as simple as running the script: /microcloud/scripts_ro/nvm_install.sh

=> Downloading nvm from git to '/home/www-data/.nvm'
=> Cloning into '/home/www-data/.nvm'...
remote: Counting objects: 6184, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6184 (delta 1), reused 0 (delta 0), pack-reused 6178
Receiving objects: 100% (6184/6184), 1.78 MiB | 0 bytes/s, done.
Resolving deltas: 100% (3822/3822), done.
Checking connectivity... done.
* (detached from v0.33.1)
  master
=> Compressing and cleaning up git repository
Counting objects: 6184, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6144/6144), done.
Writing objects: 100% (6184/6184), done.
Total 6184 (delta 4088), reused 1909 (delta 0)

=> Appending nvm source string to /home/www-data/.bashrc
=> Appending bash_completion source string to /home/www-data/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Once installed, you can either reload your bash profile for the new function to be available, or log out/in to your SSH session. You can reload your bash profile like this:

. ~/.bash_profile

You have now installed NVM and should follow the steps below in order to install NodeJS.

Installing NodeJS

Install the latest NodeJS version:

nvm install node

Install the current NodeJS LTS version:

nvm install --lts

Installing a specific NodeJS version is as simple as specifying the version number after the install parameter:

nvm install 7.7.3

Removing a NodeJS version

You can list the currently installed NodeJS versions by using the nvm list command:

nvm list
         v7.7.3
->       v7.7.4
default -> node (-> v7.7.4)
node -> stable (-> v7.7.4) (default)
nstable -> 7.7 (-> v7.7.4) (default)
iojs -> N/A (default)
vlts/* -> lts/boron (-> N/A)
lts/argon -> v4.8.1 (-> N/A)
lts/boron -> v6.10.1 (-> N/A)

The nvm uninstall command will uninstall the NodeJS version that you specify, the below example will remove 7.7.3:

nvm uninstall 7.7.3

Uninstalled node v7.7.3

Removing NVM

Removing NVM is as simple as running the installation script with the -r paremter: /microcloud/scripts_ro/nvm_install.sh -r

nvm_install.sh -r

NVM uninstalled