Home

Awesome

license: MIT

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Contents

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

n-install — introduction

Installs n, the Node.js version manager, on Unix-like platforms, without needing to install Node.js first.
Additionally, installs scripts n-update for later on-demand updating of n, and n-uninstall for uninstalling.

The simplest case is installation of n with confirmation prompt, with subsequent installation of the latest LTS Node.js version:

curl -L https://bit.ly/n-install | bash

<sup>Note: The bit.ly URL resolves to <code>https://raw.githubusercontent.com/mklement0/n-install/stable/bin/n-install</code>, i.e. a Bash script in this repository.</sup>

This is by far the simplest way to get started with both n and Node.js - even if you're looking to install only the latest LTS (long-term support) Node.js version, with no (immediate) plans to install multiple versions.

n is installed as follows:

See examples below, and Installing n for prerequisites and installation options.

Examples

See Installation options for details.

<!-- ACTIVATE THIS ONCE n ITSELF SUPPORTS WGET Note: The examples use only `curl` for brevity; to run a given command with `wget` instead, replace `curl -L` with `wget -qO-`. -->
curl -L https://bit.ly/n-install | bash
curl -L https://bit.ly/n-install | bash -s -- -y
curl -sL https://bit.ly/n-install | bash -s -- -q
curl -L https://bit.ly/n-install | bash -s -- -y lts 0.10
curl -L https://bit.ly/n-install | N_PREFIX=~/util/n bash -s -- -y

Installing n

Supported platforms and prerequisites

Among the platforms supported by n, any Unix-like platform with the following is supported:

These prerequisites are met by default on macOS and on at least some Linux platforms. What's missing from some by default is git and/or curl, which, however, are easy to install from the respective package managers (e.g., sudo apt-get install git curl on Debian, or sudo yum install git on Fedora). bash and curl are required by n itself as well.

Irrespective of the installation method chosen below, no further steps are required if your default shell is either bash, ksh, zsh, fish, or pwsh (PowerShell).
For other shells, manual updating of the relevant initialization file is required; detailed instructions are provided during installation.

Installation from GitHub

curl -L https://bit.ly/n-install | [N_PREFIX=<dir>] bash [-s -- [-y] [<version>...]]

See below for an explanation of the options; -s -- is required by Bash itself in order to pass options through to the script piped from stdin.

Before you can use n and any installed Node.js versions, you must open a new terminal tab/window or reload your shell initialization file.
For instance, if your shell is Bash and you're on Linux, you'd use . ~/.bashrc; on macOS, you'd use . ~/.bash_profile; the installer will tell you the specific file to reload on successful installation.

Caveat: If you reload the initialization file from a script (rather than interactively) - so that you can make use of n or Node.js in the remainder of the script, e.g., in order to preinstall global npm packages - make sure that you account for initialization files that prevent (re)sourcing from a non-interactive shell.
For instance, Debian and Ubuntu come with a default ~/.bashrc file that - needlessly - categorically prevents sourcing (loading) if the shell is not interactive, using the following line at the start of the script:
[ -z "$PS1" ] && return
To bypass that:

Manual installation

Note: Even when executing n-install locally, downloading from this repository occurs; specifically, helper scripts n-update and n-uninstall are downloaded - see below.

Installation options

<!-- DO NOT EDIT THE FENCED CODE BLOCK and RETAIN THIS COMMENT: The fenced code block below is updated by `make update-readme/release` with CLI usage information. -->
$ n-install --help

SYNOPSIS
  n-install [-t] [-y|-q] [-n] [-a <arch>] [<version>...]

DESCRIPTION
  Directly installs n, the Node.js version manager, which bypasses the need to
  manually install a Node.js version first.

  Additionally, installs n-update for updating n,
  and n-uninstall for uninstallation.

  On successful installation of n, the specified Node.js <version>(s)
  are installed; by default, this is the latest LTS Node.js version.
  
  To opt out, specify '-' as the only version argument.

  Supported version specifiers:

  * lts    ... the LTS (long-term stability) version
  * latest ... the latest version available overall
  * otherwise, specify an explicit version number, such as '0.12' or '0.10.35'
  
  If multiple versions are specified, the first one will be made active.

  The default installation directory is:

    ~/n
  
  which can be overridden by setting environment variable N_PREFIX to an
  absolute path before invocation; either way, however, the installation
  directory must either not exist yet or be empty.

  If your shell is bash, bsh, zsh, fish, or pwsh (PowerShell), the relevant
  initialization file will be modified so as to:
   - export environment variable $N_PREFIX to point to the installation dir.
   - ensure that the directory containing the n executable, $N_PREFIX/bin,
     is in the $PATH.
  Note that you either have to open a new terminal tab/window or re-source
  the relevant initialization file before you can use n and Node.js.
  For any other shell you'll have to make these modifications yourself.
  You can also explicitly opt out of the modification with -n.

  Options:

  -t
    Merely tests if all installation prerequisites are met, which is signaled
    with an exit code of 0.

  -y
    Assumes yes as the reply to all prompts; in other words: runs unattended
    by auto-confirming the confirmation prompt.
 
  -q
    Like -y, except that, additionally, all status messages are suppressed,
    including the information and progress bar normally displayed by n while
    installing Node.js versions.

  -n
    Suppresses updating of the relevant shell initialization file.
    For instance, this allows for custom setups where all exports are 
    "out-sourced" to an external file that is then sourced from the 
    shell-initialization file; however, note that you'll then have to edit 
    the out-sourced file *manually* - instructions will be printed.

  -a <arch>
    Specifies a specific architecture to install the specified or implied
    Node.js version(s) for, e.g. arm64 or x64.
    This overrides the default behavior of auto-selecting binaries that match
    the current system.

  For more information, see https://bit.ly/n-install-repo

PREREQUISITES
  bash ... to run this script and n itself.
  curl ... to download helper scripts from GitHub and run n itself.
  git ... to clone n's GitHub repository and update n later.
  GNU make ... to run n's installation procedure.
  
EXAMPLES
    # Install n and the latest LTS Node.js version, with 
    # interactive prompt:
  n-install 
    # Only test if installation to the specified location would work.
  N_PREFIX=~/util/n n-install -t
    # Automated installation of n, without installing Node.js
  n-install -y -
    # Automated installation of n, followed by automated installation
    # of the latest LTS and the latest-overall Node.js versions, as well
    # as the latest 0.8.x version.
  n-install -y lts latest 0.8

Updating n

Run n-update on demand to update n itself to the latest version.
n-update -y skips the confirmation prompt.

Manual updating

If, for some reason, n-update doesn't work or isn't available, run the following to update n:

Uninstalling n

Run n-uninstall to uninstall n as well as the Node.js versions that were installed with it.
n-uninstall -y skips the confirmation prompt - use with caution.

Manual uninstallation

If, for some reason, n-uninstall doesn't work, do the following:

<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'LICENSE.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. -->

License

Copyright (c) 2015-2021 Michael Klement mklement0@gmail.com (http://same2u.net), released under the MIT license.

Acknowledgements

This project gratefully depends on the following open-source components, according to the terms of their respective licenses.

npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D) denotes a development-time-only dependency, (O) an optional dependency, and (P) a peer dependency.

<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the dependencies from 'package.json'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. -->

npm dependencies

<!-- DO NOT EDIT THE NEXT CHAPTER and RETAIN THIS COMMENT: The next chapter is updated by `make update-readme/release` with the contents of 'CHANGELOG.md'. ALSO, LEAVE AT LEAST 1 BLANK LINE AFTER THIS COMMENT. -->

Changelog

Versioning complies with semantic versioning (semver).

<!-- NOTE: An entry template for a new version is automatically added each time `make version` is called. Fill in changes afterwards. -->