diff --git a/README.md b/README.md index 725c5cd..60670d6 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ To take ownership of the system directories (option 1): If `npm` is not yet available, one way to bootstrap an install is to download and run `n` directly. To install the `lts` version of Node.js: - curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s lts + curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s install lts # If you want n installed, you can use npm now. npm install -g n @@ -237,6 +237,18 @@ Use `n` to access cached versions (already downloaded) without internet availabl n --offline 12 +Remove the cache version after installing using `--cleanup`. This is particularly useful for a one-shot install, like in a docker container. + + curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s install --cleanup lts + +The `--download` option can be used in two ways, to download a version into cache but not make active: + + n --download lts + +or to download a possibly missing version for `n run`, `n exec`, and `n which`: + + n --download run 18.3 my-script.js + Display diagnostics to help resolve problems: n doctor diff --git a/bin/n b/bin/n index 44daebf..203fe19 100755 --- a/bin/n +++ b/bin/n @@ -133,6 +133,7 @@ g_active_node= g_target_node= DOWNLOAD=false # set to opt-out of activate (install), and opt-in to download (run, exec) +CLEANUP=false # remove cached download after install ARCH= SHOW_VERBOSE_LOG="true" OFFLINE=false @@ -397,6 +398,7 @@ Options: -p, --preserve Preserve npm and npx during install of Node.js -q, --quiet Disable curl output. Disable log messages processing "auto" and "engine" labels. -d, --download Download if necessary, and don't make active + --cleanup Remove cached version after install -a, --arch Override system architecture --offline Resolve target version against cached downloads instead of internet lookup --all ls-remote displays all matches instead of last 20 @@ -757,6 +759,12 @@ activate() { printf 'If "node --version" shows the old version then start a new shell, or reset the location hash with:\nhash -r (for bash, zsh, ash, dash, and ksh)\nrehash (for csh and tcsh)\n' fi fi + + if [[ "$CLEANUP" == "true" ]]; then + log "cleanup" "removing cached $version" + remove_versions "$version" + fi + } # @@ -1672,6 +1680,7 @@ while [[ $# -ne 0 ]]; do -h|--help|help) display_help; exit ;; -q|--quiet) set_quiet ;; -d|--download) DOWNLOAD="true" ;; + --cleanup) CLEANUP="true" ;; --offline) OFFLINE="true" ;; --insecure) set_insecure ;; -p|--preserve) N_PRESERVE_NPM="true" N_PRESERVE_COREPACK="true" ;;