返回

Fixing "nvm command not found" on macOS Ventura

前端

NVM Installation Troubleshooting: Resolving "nvm command not found" on macOS Ventura

Introduction

nvm, the ubiquitous Node version manager, has long been a cornerstone of the JavaScript development ecosystem. However, recent updates to macOS have introduced a wrinkle in the installation process, leading to the dreaded "nvm command not found" error. Fear not, for this quandary can be overcome with a quick fix.

The Problem: zsh vs. bash

macOS Ventura has ushered in zsh as the default shell, replacing the traditional bash. This subtle shift has a ripple effect on nvm's installation, as it relies on the .bash_profile file. Since zsh doesn't recognize this file, the nvm command remains elusive.

The Solution: Embracing zsh

To rectify the situation, we must acknowledge the zsh supremacy and modify the appropriate file. Follow these steps to conquer the error:

  1. Navigate to your home directory: Open Terminal and type cd ~.
  2. Create the .zshrc file: If it doesn't exist, create the .zshrc file using touch .zshrc.
  3. Edit the .zshrc file: Open the .zshrc file in your preferred text editor.
  4. Add nvm initialization: Paste the following line into the file:
source ~/.nvm/nvm.sh
  1. Save the changes: Exit the text editor and save the .zshrc file.
  2. Reload the zsh configuration: Type source ~/.zshrc in Terminal to activate the changes.

Verifying Success

To confirm that nvm is now at your command, type nvm in Terminal. You should be greeted with a list of available Node versions. If the command still fails, double-check that you followed the steps correctly and that the .zshrc file is properly sourced.

Conclusion

While macOS Ventura's shift to zsh may have initially thrown a spanner in the works, the solution to the "nvm command not found" error is both straightforward and effective. By embracing the new shell's ways, you can restore nvm to its rightful place as your trusty Node version manager. May your JavaScript endeavors forever flourish!