Are you tired of Node.js and want to uninstall it from your Mac? Don't worry, we've got you covered! In this article, we will guide you on how to uninstall Node.js from your Mac step by step. Whether you want to switch to a different version of Node.js or you simply don't need it anymore, follow the instructions below to remove Node.js completely from your Mac.
Why Uninstall Node.js?
Node.js is a popular JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to build scalable and high-performance web applications. However, there might be several reasons why you want to uninstall Node.js from your Mac:
- You want to switch to a different version of Node.js
- You no longer need Node.js for your projects
- You encountered issues or conflicts with Node.js
Step-by-Step Guide to Uninstall Node.js on Mac
Follow the steps below to uninstall Node.js from your Mac:
Step 1: Check the Installed Version of Node.js
Before uninstalling Node.js, it's essential to know which version is currently installed on your Mac. Open the Terminal application and type the following command:
node -v
This command will display the installed version of Node.js. Note it down for future reference.
Step 2: Uninstall Node.js Using Terminal
To uninstall Node.js, you need to use the Terminal application. Open the Terminal and follow the steps below:
- Type the following command to uninstall Node.js and npm:
sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/{npm,},node*,npm*,man/{man1/node*,man3/npm*}}
This command will remove all the files and directories related to Node.js and npm from your Mac.
- Verify the uninstallation by typing the following command:
node -v
If Node.js is uninstalled successfully, the Terminal will display an error message such as “zsh: command not found: node”.
Step 3: Remove Node.js from $PATH Variable
Although Node.js is uninstalled, there might still be references to it in your $PATH variable. To remove these references, follow the steps below:
- Type the following command to open the .bash_profile file:
open ~/.bash_profile
- In the .bash_profile file, delete any lines that reference Node.js or npm.
- Save the changes and close the .bash_profile file.
After removing the references to Node.js from the $PATH variable, it won't be recognized by the Terminal anymore.
Step 4: Verify the Uninstallation
To verify that Node.js is completely uninstalled from your Mac, follow these steps:
- Open a new Terminal window.
- Type the following command:
node -v
If Node.js is successfully uninstalled, the Terminal will display an error message, as mentioned in Step 2.
Additional Steps (Optional)
If you want to be thorough and remove any leftover files or directories related to Node.js, you can follow these additional steps:
Step 1: Remove Node.js Global Modules
If you have installed any global modules using npm, you can remove them by typing the following command:
sudo rm -rf /usr/local/lib/node_modules
This command will remove the global modules directory.
Step 2: Remove Node.js Configuration Files
To remove any Node.js configuration files, type the following commands:
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
These commands will remove the npm and node-gyp directories from your home directory.
Step 3: Remove Node.js Data Files
If you want to remove any data files associated with Node.js, type the following commands:
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
These commands will remove the Node.js manual page and DTrace files.
Conclusion
Uninstalling Node.js from your Mac is a straightforward process. By following the steps outlined in this article, you can remove Node.js and all its associated files and directories. Remember to check the installed version of Node.js before uninstalling and verify the uninstallation afterward. If you encounter any issues or conflicts during the uninstallation process, feel free to seek further assistance from the Node.js community or consult the official documentation.