Node.js에서 n은 손쉽게 Node.js 환경을 바꿔주고 적용해주는 유명한 모듈입니다.
Python도 비슷하지만 Node.js 로 개발된 프로그램에 따라 특정 Node.js 환경에서만 실행되는 경우가 있어, 다양한 테스트를 위해 종종 Node.js 환경을 바꿔야하는 경우가 있습니다.
n의 기능은 다양하지만 대표적인 몇개의 기능을 살펴보면 아래와 같습니다.
- 특정버전 설치
- 삭제
- 적용
아래는 n -h 명령어를 썼을때 뜨는 상세설명입니다. 궁굼하신 분은 더 보기를 눌러 확인해보세요.
더보기
Usage: n [options] [COMMAND] [args]
Commands:
n Display downloaded Node.js versions and install selection
n latest Install the latest Node.js release (downloading if necessary)
n lts Install the latest LTS Node.js release (downloading if necessary)
n <version> Install Node.js <version> (downloading if necessary)
n install <version> Install Node.js <version> (downloading if necessary)
n run <version> [args ...] Execute downloaded Node.js <version> with [args ...]
n which <version> Output path for downloaded node <version>
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
n rm <version ...> Remove the given downloaded version(s)
n prune Remove all downloaded versions except the installed version
n --latest Output the latest Node.js version available
n --lts Output the latest LTS Node.js version available
n ls Output downloaded versions
n ls-remote [version] Output matching versions available for download
n uninstall Remove the installed Node.js
Options:
-V, --version Output version of n
-h, --help Display help information
-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
-a, --arch Override system architecture
--all ls-remote displays all matches instead of last 20
--insecure Turn off certificate checking for https requests (may be needed from behind a proxy server)
--use-xz/--no-use-xz Override automatic detection of xz support and enable/disable use of xz compressed node downloads.
Aliases:
install: i
latest: current
ls: list
lsr: ls-remote
lts: stable
rm: -
run: use, as
which: bin
Versions:
Numeric version numbers can be complete or incomplete, with an optional leading 'v'.
Versions can also be specified by label, or codename,
and other downloadable releases by <remote-folder>/<version>
4.9.1, 8, v6.1 Numeric versions
lts Newest Long Term Support official release
latest, current Newest official release
auto Read version from file: .n-node-version, .node-version, .nvmrc, or package.json
engine Read version from package.json
boron, carbon Codenames for release streams
lts_latest Node.js support aliases
and nightly, rc/10 et al
설치방법
sudo npm install -g n
특정 Node.js 버전 설치 방법
$> sudo n install 18
installing : node-v18.16.0
mkdir : /usr/local/n/versions/node/18.16.0
fetch : https://nodejs.org/dist/v18.16.0/node-v18.16.0-darwin-arm64.tar.xz
copying : node/18.16.0
installed : v18.16.0 to /usr/local/bin/node
active : v19.6.0 at /opt/homebrew/bin/node
$> sudo n install 19
installing : node-v19.9.0
mkdir : /usr/local/n/versions/node/19.9.0
fetch : https://nodejs.org/dist/v19.9.0/node-v19.9.0-darwin-arm64.tar.xz
copying : node/19.9.0
installed : v19.9.0 to /usr/local/bin/node
active : v19.6.0 at /opt/homebrew/bin/node
Node.js 버전 교체적용 방법
$> sudo n
※ 맥에서 brew를 통한 node.js 설치를 진행한 사람의 경우 brew uninstall nodejs 해주신 후 진행하시기 바랍니다.
반응형
'자바스크립트 > Node JS' 카테고리의 다른 글
Slack API (bolt)를 활용한 Bot 만들기 (0) | 2023.08.28 |
---|---|
NPM 프로젝트 라이브러리 자동 최신버전 반영 방법 (0) | 2023.05.05 |
sharp 설치 실패 해결 방안 (0) | 2023.05.04 |