Install Node.js LTS on Windows; reopen the terminal afterwards so PATH takes effect
# Windows(官方 LTS 安装包走 winget)
winget install OpenJS.NodeJS.LTSSet up Node.js from scratch: install on Windows and Linux/macOS, switch versions with nvm or fnm, switch registries, enable pnpm, scaffold projects and fix common errors.
Install Node.js LTS on Windows; reopen the terminal afterwards so PATH takes effect
# Windows(官方 LTS 安装包走 winget)
winget install OpenJS.NodeJS.LTSUse Homebrew on macOS and the NodeSource repo on Ubuntu to install a specific major version
# macOS
brew install node@20
# Ubuntu / Debian
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejsInstall fnm on Windows as the version manager (faster than nvm-windows, no admin rights needed)
winget install Schniz.fnmInstall and switch to Node 20, then list locally installed versions
fnm install 20
fnm use 20
fnm listEnable fnm env --use-on-cd in your PowerShell profile to switch versions automatically when entering a directory
Install and switch versions with nvm, and set the default version
# macOS / Linux
nvm install 20
nvm use 20
nvm alias default 20Enable pnpm; prefer corepack so the whole team uses the same pnpm version
corepack enable pnpm
npm install -g pnpm@9Switch npm to a China mirror and verify the active registry
npm config set registry https://registry.npmmirror.com
npm config get registrypnpm keeps its own config, so set the mirror separately
pnpm config set registry https://registry.npmmirror.comWrite this into the project .npmrc so the mirror only applies to this project
registry=https://registry.npmmirror.com
strict-ssl=trueConfigure npm to go through a corporate or local proxy
npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890Remove proxy settings after turning the proxy off, otherwise installs keep timing out
npm config delete proxy
npm config delete https-proxyCheck the Node/npm versions and the global install prefix
node -v
npm -v
npm config get prefixShow the global node_modules path when debugging global packages
npm root -gSet NODE_ENV with setx on Windows or by appending to the shell profile on macOS/Linux
# Windows PowerShell(永久生效,需重开终端)
setx NODE_ENV development
# macOS / Linux
echo 'export NODE_ENV=development' >> ~/.zshrcVerify the npm global bin directory is on PATH, otherwise global commands are not found
# Windows
echo %APPDATA%\npm
# macOS / Linux
echo $PATH | tr ":" "\n" | grep npmScaffold a Vue + TypeScript project with Vite
npm create vite@latest my-app -- --template vue-tsInitialize a minimal project and run the entry file directly
npm init -y
node index.jsInstall dependencies and start the local dev server
npm install
npm run devBuild for production and verify the output with preview
npm run build
npm run previewPrint the active Node version and platform to confirm the effective runtime
node -e "console.log(process.version, process.platform)"Install the Vue, ESLint and Prettier extensions from the CLI so teams can script it
code --install-extension Vue.volar
code --install-extension dbaeumer.vscode-eslint
code --install-extension esbenp.prettier-vscodePin the Node version in the repo root so nvm use picks it up automatically
echo 20 > .nvmrcDeclare the engines field so incompatible Node versions are flagged on install
npm pkg set engines.node=">=20"When the version looks wrong, check which executable the command actually resolves to
# Windows
where node
# macOS / Linux
which -a nodeClean the npm cache when installs fail integrity checks
npm cache verify
npm cache clean --forceThe next install re-downloads everything, which is noticeably slower on bad networks
Allow local scripts when PowerShell refuses to load npm.ps1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUserTemporarily disable certificate checks when the corporate MITM certificate causes UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm config set strict-ssl falseOnly for intranet setups; set it back to true afterwards to avoid MITM risk
Find the process occupying the dev server port before deciding to kill it
# Windows
netstat -ano | findstr :5173
# macOS / Linux
lsof -i :5173Fix EACCES on global installs by switching the global prefix to a user directory on Linux/macOS
npm config set prefix ~/.npm-global
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrcThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.