Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Installs n, the Node.js version manager, without needing to install Node.js first: curl -Lhttps://bit.ly/n-install | bash

NotificationsYou must be signed in to change notification settings

mklement0/n-install

Repository files navigation

license: MIT

Contents

n-install — introduction

Installsn, theNode.js version manager, on Unix-like platforms,without needing to install Node.js first.
Additionally, installs scriptsn-update for later on-demand updating ofn, andn-uninstall for uninstalling.

The simplest case isinstallation ofn with confirmation prompt, with subsequentinstallation of the latest LTS Node.js version:

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

Note: The bit.ly URL resolves tohttps://raw.githubusercontent.com/mklement0/n-install/stable/bin/n-install, i.e. a Bash script in this repository.

This is by farthe simplest way to get started with bothn 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 installmultiple versions.

n is installed as follows:

  • The installation target is adedicated directory, whichdefaults to~/n and can be overridden with environment variableN_PREFIX; n itself as well as the active Node.js version are placed there.
    • When overriding, it is advisable to choose a user location - typically, a subfolder of~ (at any level) - so as to avoid the need to usesudo for installation of globalnpm packages.
    • Either way, the target directory must either not exist yet or be empty.
    • Using a dedicated directory to hold bothn and the Node.js versions greatly simplifies later uninstallation.
  • If your shell (your default interactive shell, as reflected in environment variable$SHELL) isbash,ksh,zsh,fish, orpwsh (PowerShell), the relevant shell initialization file is modified:
    • Environment variableN_PREFIX is defined to point to the installation directory.
    • Directory$N_PREFIX/bin is appended to the$PATH, unless already present.
    • For other shells, these modification must be performed manually; instructions are provided during installation.
    • Note: You can also suppress modification with the-n option.
    • Note: If you want to override what shell's initialization file is updated, set theSHELL environment variable to that shell's file name (e.g.,fish) before calling the installation command; e.g., from a POSIX-compatible shell:curl -L https://bit.ly/n-install | SHELL=fish bash; similarly, on uninstallation you'll have to useSHELL=fish n-uninstall
  • By default, the latest LTS Node.js version is installed; you can suppress that or even specify multiple Node.js versions to install.
  • Note that any preexistingn, Node.js installation must be removed before using this installation method.
  • All installation prerequisites are met by default on macOS and some Linux distros; notably,git andcurl must be present - seeInstalling n for details.
  • After installation,be sure to open a new terminal tab or window or reload your shell initialization file before attempting to usen / Node.js.

See examplesbelow, andInstalling n for prerequisites and installation options.

Examples

SeeInstallation options for details.

  • Installation with confirmation prompt to default location$HOME/n and installation of the latest LTS Node.js version:
curl -L https://bit.ly/n-install| bash
  • Automated installation to default location$HOME/n and installation of the latest LTS Node.js version:
curl -L https://bit.ly/n-install| bash -s -- -y
  • Automated,quiet installation to default location$HOME/n and installation of the latest LTS Node.js version;no status informationis displayed:
curl -sL https://bit.ly/n-install| bash -s -- -q
  • Automated installation to the default location, with subsequent installation of the latest LTS(Long Term Support) version, and the latest v22 release:
curl -L https://bit.ly/n-install| bash -s -- -y lts 22
  • Automated installation to custom location~/util/n, with subsequent installation of the latest LTS Node.js version:
curl -L https://bit.ly/n-install| N_PREFIX=~/util/n bash -s -- -y

Installing n

Supported platforms and prerequisites

Among the platforms supported byn, 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 isgit and/orcurl, which, however, are easy to install from the respective package managers (e.g.,sudo apt-get install git curl on Debian, orsudo yum install git on Fedora).bash andcurl are required byn itself as well.

Irrespective of the installation method chosen below, no further steps are required if your default shell is eitherbash,ksh,zsh,fish, orpwsh (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 usen and any installed Node.js versions, you mustopen a new terminal tab/windowor reload your shell initialization file.
For instance, if your shell is Bash and you're onLinux, you'd use. ~/.bashrc; onmacOS, you'd use. ~/.bash_profile;the installer will tell you the specific file to reload on successful installation.

Caveat: If youreload the initialization file from ascript (rather than interactively) - so that you can make use ofn 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 anon-interactive shell.
For instance,Debian andUbuntu 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:

  • Inbash, precede the reload (sourcing) command withset -i to simulate an interactive environment:

        set -i       # turn on interactive mode    . ~/.bashrc  # reload (source) the initialization file    set +i       # turn interactive mode back off
  • Alternatively, invoke your script as a whole withbash --norc --noprofile -i <script>, which processes it in interactive (-i) mode.

    • This would work analogously forksh andzsh as well.

Manual installation

  • Downloadthisbash script asn-install.
  • Make it executable withchmod +x.
  • Move or symlink it to a directory in your$PATH.
  • Invoken-install as detailed below.
  • Open a new terminal tab/window or reload your shell initialization file before usingn and any installed Node.js versions - see GitHub instructions above.

Note: Even when executingn-install locally, downloading from this repositoryoccurs; specifically, helper scriptsn-update andn-uninstall are downloaded - see below.

Installation options

$ n-install --helpSYNOPSIS  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 '22' or '22.13'    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-repoPREREQUISITES  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

Runn-update on demand to updaten 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 updaten:

  • cd "$N_PREFIX/n/.repo" && git fetch --depth 1 --quiet && git reset --hard origin/master --quiet && PREFIX="$N_PREFIX" make install && cd -

Uninstalling n

Runn-uninstall to uninstalln 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:

  • Remove theN_PREFIX environment-variable definition and associatedPATH modification from your shell's initialization file.

  • Remove the directory thatN_PREFIX points to:

    • Be sure that that directory contains no content unrelated ton that you may want to preserve.
    • If$N_PREFIX is not defined, look in the default installation location,~/n.

License

Copyright (c) 2015-2021 Michael Klementmklement0@gmail.com (http://same2u.net), released under theMIT 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; theabsence of a suffix denotes a requiredrun-time dependency:(D) denotes adevelopment-time-only dependency,(O) anoptional dependency, and(P) apeer dependency.

npm dependencies

Changelog

Versioning complies withsemantic versioning (semver).

  • v0.6.5 (2025-02-09):

    • [enhancement] Versions to install may now be specified as major version numbers only, e.g.22
    • [enhancement] Interactive prompt is now less verbose in that opt-outs aren't explicitly mentioned.
  • v0.6.4 (2025-01-23):

    • [fix] SHA-256 checksum-utility command-line construction code updated for new macOS version.
  • v0.6.3 (2022-04-26):

    • [fix] Restored old shell-initialization file ID string, so as not to break existing installations.
  • v0.6.2 (2022-04-26):

    • [fix] Short URL domain names updated tobit.ly, given thatgit.io is being retired (thanks, @SukkaW).
  • v0.6.1 (2021-03-12):

    • [fix]fish initialization-file modification corrected.
  • v0.6.0 (2021-03-12):

    • [enhancement] Added initialization-files support forfish andpwsh (PowerShell).
  • v0.5.1 (2020-01-10):

    • [fix] Fixes #28: support for a custom zsh initialization-file directory via environment variableZDOTDIR.
  • v0.5.0 (2018-07-25):

    • [breaking change] It is now the LTS version (long-term support,lts) version that is installed by default,because the previous default,stable, is obsolete and no longer meaningful: the minorversion number being odd or even no loger carries meaning since Node.js embraced semantic versioning.Seehttps://nodejs.org/en/blog/release/v6.0.0/#current-what-happened-to-stable.From now on, choose eitherlts for the latest LTS version orlatest for thelatest in-development version, whichNode.Js now callscurrent.
  • v0.4.1 (2018-07-24):

    • Adds support for pass-thru option-a <arch>, so as to allow overriding the target architecture when installingthe initial Node.js version(s) - implementsrequest #22.
  • v0.4.0 (2017-10-26):

    • [enhancement] The integrity of helper scriptsn-update andn-uninstall, which are downloaded byn-install fromthis repo, is now verified via SHA-256 checksums embedded inn-install.
  • v0.3.7 (2017-10-25):

    • [doc] Clarified that even during local execution after having manually downloadedn-install helper scripts are downloaded from this repo.
  • v0.3.6 (2017-09-03):

    • [enhancement] Installation and updating ofn now guards against unexpected core.autocrlf settings.
    • [enhancement] Status and error messages improved to consistently mention version spec. 'lts'
  • v0.3.5 (2017-02-25):

    • [doc] Fixed manualn update instructions, added LTS version hints to CLI help.
  • v0.3.4 (2017-01-27):

    • [fix] for#10:n-update could fail to updaten due to how it updated the localcopy of then repo.
      To update an already-installed copy ofn-update, run the following:
      • cd "$N_PREFIX/bin"
      • curl https://raw.githubusercontent.com/mklement0/n-install/stable/bin/n-update > n-update
      • and then runn-update again.
  • v0.3.3 (2016-06-01):

    • [security] Switched to https:// URLs.
  • v0.3.2 (2016-02-20):

    • [enhancement] New option-q (quiet mode) skips prompts, like-y, and additionally suppresses all status output.
  • v0.3.1 (2016-02-05):

    • [optimization]git clone andgit pull now use--depth 1 to only get the latestrevision ofn, which is all that is needed; tip of the hat to @steelbrain.
  • v0.3.0 (2016-01-14):

    • [enhancement] Support forn's symboliclts version specifier that installsthe latest LTS (Long Term Support) version.
  • v0.2.0 (2015-12-24):

    • [enhancement] New option-n allows suppressing modification of shell-initialization files, to allow for setups whereall exports are "out-sourced" to an external file that is then sourced from the shell-initialization file; note that use of-ntherefore requires performing the modificationsmanually.
  • v0.1.9 (2015-12-18):

    • [fix] Runtime Bash version check fixed; verified to work on at least 3.1.x - unclear, how far back it'll work.
  • v0.1.8 (2015-12-18):

    • [enhancement] Added runtime check to ensure that the Bash version runningn-install is 3.2 or higher.
  • v0.1.7 (2015-11-23):

    • [doc] Removed references to io.js, now the project has merged with Node.js.
    • [doc] Added better tip for simulating an interactive environment for reloading a Bash initialization file.
  • v0.1.6 (2015-10-08):

    • [doc] CLI usage-help corrections.
  • v0.1.5 (2015-08-09):

    • [doc] Improved post-installation instructions.
  • v0.1.4 (2015-07-27):

    • [enhancement] Success message now mentions manually re-sourcing the shell initialization file as an alternative to opening a new terminal tab/window.
  • v0.1.3 (2015-07-04):

    • [robustness] Ifmake is found not to beGNUmake, an attempt is made to usegmake instead.
    • [doc]--version now also outputs the project's home URL; read-me improvements.
  • v0.1.2 (2015-06-21):

    • [doc] Examples revised.
  • v0.1.1 (2015-06-21):

    • [doc] Examples revised.
  • v0.1.0 (2015-06-20):

    • Initial release.

About

Installs n, the Node.js version manager, without needing to install Node.js first: curl -Lhttps://bit.ly/n-install | bash

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp