How to install NodeJS via NVM under FreeBSD 12

NVM is a version manager utility for NodeJS which is designed to be installed per-user. This means that all your nodeJS and NPM is run directly from your own home directory. This is useful for systems where you do not have root access and you need to install npm that are global.

In this case, when you install global packages, they are installed to your own home directory, so you will never run into super-user issues.

NVM is not directly supported under FreeBSD because there aren’t any pre-built binaries for FreeBSD.

However, we can still use NVM under FreeBSD with the steps below.

Install Git

You will need to install Git first as NVM pulls the latest files needed for installation from the Git repos.

I will be using pkg for this installation.

pkg install git

Install Curl

On the NVM website, there are 2 options to pull the install script and run it, I will be using the curl command

First, install the curl utility

pkg install curl

Next, install the script

curl -o- | bash

Install make

Nvm requires the game utility in order to compile NodeJS executables for your FreeBSD system

pkg install gmake

Point the compilers to the correct location

Nvm requires the C compilers to be present. On FreeBSD, it is installed in /usr/bin

export CC=/usr/bin/cc

export CXX=/usr/bin/c++

Install Nvm

Now you are ready to install the nvm utility, since we have installed the curl utility, we will use the curl command to download the install script and install Nvm

curl -o- | bash

After Nvm has been installed successfully, Nvm will also attempt to add the path information to your .bashrc file so that you are able to execute the utility. If you are using other shells such as zsh, please add the paths to your .zshrc file.

Install NodeJS

Now that Nvm is on your system, you can now install NodeJS.

nvm install 12.8.3

This will get nvm to pull the latest source for the 12.18.3 version and build it natively on your system.

Leave a Reply

Your email address will not be published. Required fields are marked *