# Remove the GPG keyring file associated with the old repository sudorm /etc/apt/keyrings/nodesource.gpg # Remove the old repository's list file sudorm /etc/apt/sources.list.d/nodesource.list
初始化安装仓库
1 2 3 4 5 6 7 8 9 10 11 12
# Define the desired Node.js major version NODE_MAJOR=22 # Update local package index sudo apt-get update # Install necessary packages for downloading and verifying new repository information sudo apt-get install -y ca-certificates curl gnupg # Create a directory for the new repository's keyring, if it doesn't exist sudomkdir -p /etc/apt/keyrings # Download the new repository's GPG key and save it in the keyring directory curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg # Add the new repository's source list with its GPG key for package verification echo"deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | sudotee /etc/apt/sources.list.d/nodesource.list
安装 NOde.js
1 2 3 4
# Update local package index to recognize the new repository sudo apt-get update # Install Node.js from the new repository sudo apt-get install -y nodejs
配置 npm 使用国内镜像
1
npm config set registry https://registry.npmmirror.com