diff --git a/README.md b/README.md index 5dd92b4a..b16fa162 100644 --- a/README.md +++ b/README.md @@ -266,11 +266,13 @@ Another example is the Node.js [unofficial-builds project](https://github.com/no export N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release -You may need to specify the architecture explicitly if not autodetected by `n`, such as using `musl` `libc` on Alpine: +You may need to specify the architecture explicitly if not autodetected by `n`, such as using `musl` `libc` on Alpine. You can do that with `N_ARCH` or `--arch`: export N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release + export N_ARCH=x64-musl apk add bash curl libstdc++ - n --arch x64-musl install lts + n install lts + n --arch x64-musl install lts # using a flag If the custom mirror requires authentication you can add the [url-encoded](https://urlencode.org) username and password into the URL. e.g. diff --git a/bin/n b/bin/n index ac2c961d..cf9db8ff 100755 --- a/bin/n +++ b/bin/n @@ -134,7 +134,7 @@ 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= +ARCH="${N_ARCH-}" SHOW_VERBOSE_LOG="true" OFFLINE=false @@ -1030,20 +1030,25 @@ function display_tarball_platform() { MINGW*) >&2 echo_red "Git BASH (MSYS) is not supported by n" ;; esac - local arch="unexpected_arch" - local uname_m="$(uname -m)" - case "${uname_m}" in - x86_64) arch=x64 ;; - i386 | i686) arch="x86" ;; - aarch64) arch=arm64 ;; - armv8l) arch=arm64 ;; # armv8l probably supports arm64, and there is no specific armv8l build so give it a go - *) - # e.g. armv6l, armv7l, arm64 - arch="${uname_m}" - ;; - esac - # Override from command line, or version specific adjustment. - [ -n "$ARCH" ] && arch="$ARCH" + # architecture might already be known from (priority order): + # * --arch flag on the command line, + # * otherwise, from $N_ARCH + # * otherwise from version specific adjustment (if applicable, see update_arch_settings_for_version) + local arch="$ARCH" + if [[ -z "$arch" ]]; then + arch="unexpected_arch" + local uname_m="$(uname -m)" + case "${uname_m}" in + x86_64) arch=x64 ;; + i386 | i686) arch="x86" ;; + aarch64) arch=arm64 ;; + armv8l) arch=arm64 ;; # armv8l probably supports arm64, and there is no specific armv8l build so give it a go + *) + # e.g. armv6l, armv7l, arm64 + arch="${uname_m}" + ;; + esac + fi echo "${os}-${arch}" } @@ -1519,6 +1524,7 @@ function show_diagnostics() { echo "node downloads mirror: $(display_masked_url "${N_NODE_DOWNLOAD_MIRROR}")" echo "install destination: ${N_PREFIX}" [[ -n "${N_PREFIX}" ]] && echo "PATH: ${PATH}" + [[ -n "$N_ARCH" ]] && echo "default arch: $N_ARCH" echo "ls-remote max matches: ${N_MAX_REMOTE_MATCHES}" [[ -n "${N_PRESERVE_NPM}" ]] && echo "installs preserve npm by default" [[ -n "${N_PRESERVE_COREPACK}" ]] && echo "installs preserve corepack by default"