Skip to content

System‐wide installation

Michael Klement edited this page Feb 24, 2017 · 1 revision

n-install isn't really designed for system-wide installation, but you can do it with a few extra steps.

A possible use case is the need to run scripts using a different user identity.

Here's an example that installs to /usr/local/opt/n, preinstalling the LTS node version`:

curl -L https://git.io/n-install | N_PREFIX=/usr/local/opt/n bash -s -- lts
  • You may need sudo; on macOS, if you have Homebrew installed, you do not. If you do need sudo, you'll later also need it to run n and to install npm packages globally.

  • While your shell initialization file(s) are still updated to define env. variable N_PREFIX and to add /usr/local/opt/n/bin to the PATH, you must also define export N_PREFIX=/usr/local/opt/n in a global shell initialization file such as /etc/profile/ (sh, bash, ksh) or /etc/zshenv (zsh); add the following line (requires sudo):

      export N_PREFIX=/usr/local/opt/n; PATH+=":$N_PREFIX/bin"
    

    In the simplest case:

    sudo sh -c "echo 'export N_PREFIX=/usr/local/opt/n; export PATH+=\":\$N_PREFIX/bin\"' >>/etc/profile"
    

    You must have N_PREFIX defined for n to work properly, but if you'd rather not modify the PATH env. variable, you can create symlinks in /usr/local/bin as follows:

    cd /usr/local/bin
    ln -s ../opt/n/bin/* .
    
  • When you later uninstall n with n-uninstall, you'll have to manually revert the changes to the global shell initialization files, and, if applicable, remove the manually created n npm n-uninstall n-update symlinks.

Clone this wiki locally