Modify node version on Mac

        When developing background services based on Node.js, you will encounter various inexplicable problems. After investigation, you will find that many of them are related to the node version. Therefore, we often need to switch node versions.

1. To view the current node version, you can use the command: node -v

(base) xay@XAYsdeMacBook-Pro ~ % node -v
v19.8.1

2. To install tool n, you can use the following command: npm install n -g.
If the download speed is slow, you can use Taobao source

# 或使用如下语句解决npm速度慢的问题
npm install --registry=https://registry.npm.taobao.org

(base) xay@XAYsdeMacBook-Pro ~ % npm install n -g

3. To switch the node version, you can refer to the following command format: n version number (14.19.0)

(base) xay@XAYsdeMacBook-Pro ~ % n 14.19.0

If you encounter an error: Error: sudo required (or change ownership, or define N_PREFIX)

Add sudo before the code

(base) xay@XAYsdeMacBook-Pro ~ % sudo n 14.19.0

4. Check the current version

(base) xay@XAYsdeMacBook-Pro ~ % node -v
v14.19.0

Small tips:

n latest // Install the latest version n stable // Update to the latest stable version

Guess you like

Origin blog.csdn.net/weixin_42823298/article/details/129928352