Upgrade Node. js Version and Pit in mac Environment with n Upgrade Tool

  • 2021-07-21 07:08:25
  • OfStack

1. Upgrade Node. js with n

When I recently installed an nodejs tool with NPM, I found that my version of nodejs is a bit old. This is not a big problem, just upgrade it. Of course, re-starting from the latest version of nodejs. org is a method, but I think there should be a simpler method, that is, using n toolkit. We can use NPM to install n toolkit first, and then use it to upgrade nodejs, which is 10 points convenient.


sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Above, this is using n to install the latest stable version of nodejs.

n is an Node toolkit that provides several upgrade command parameters:

n displays the installed version of Node n latest Install the latest version of Node n stable Install the latest stable version of Node n lts Install the latest long-term maintenance version (lts) Node n < version > Install Node according to the version number provided

For example, you want to install the specified version number:


sudo n 0.8.21

1 Once the installation is completed, you can confirm the installed version by the following command:


node -v

2. Testing in mac Environment

This environment is based on Mac OS X EI Capitan V 10.11. 4, which should be a common fault in mac environment.

Enter (online method) on the command line:


sudo npm install -g n

Then enter it again sudo n stable

Then the command line started to show the percentage, slowly changing from 1% to 100%. I thought the update was finished, and the result was. . .

Input node -v Show:


 dyld: Symbol not found:
 Referenced from: /usr/local/bin/node
 Expected in: /usr/lib/libstdc++.6.dylib
 Trace/BPT trap: 5

Then I know that trouble is coming. In a word, it is like this after npm. Baidu has various methods on the Internet, such as reloading gcc, unloading node, reloading, adding environment variables and so on. . . .

Anyway, all kinds of methods are different. I really don't know whether n can be used on mac. Anyway, many people have not solved similar methods.

Discard the n tool

Since n can't upgrade my mac, and it also damaged the node system, and no effective related solutions were found on the Internet, there was no choice but to uninstall node completely and then reinstall it.

Because node installed by brew is used, it is used with brew uninstall node After uninstalling node, it was found that the problem was still not solved.

Then 1 must be that this command did not completely uninstall node, so I had to uninstall it manually.

cd to Root


 find . -name "node"
 find . -name "npm"

Delete all search results related to node

Re- brew instll node

err will be prompted at the end of installation:


 Error: The `brew link` step did not complete successfully
 The formula built, but is not symlinked into /usr/local
 Could not symlink lib/dtrace/node.d
 Target /usr/local/lib/dtrace/node.d
 already exists. You may want to remove it:
 rm '/usr/local/lib/dtrace/node.d'

 To force the link and overwrite all conflicting files:
 brew link --overwrite node

Don't panic, take the error prompt to operate


rm '/usr/local/lib/dtrace/node.d' `  
brew link --overwrite node

Rerun command discovery node -v The installation was successful. npm -v After confirmation, reinstall the results.

node is back to normal! Therefore, in the mac environment, use the n upgrade tool with caution to upgrade the node. js version.

Summarize

The above is the whole content of this article. I hope the content of this article can bring 1 certain help to everyone's study or work. If you have any questions, you can leave a message for communication.


Related articles: