Mac solved command not found: compdef

Follow these steps to install nvm using homebrew
https://www.wdiaz.org/how-to-install-nvm-with-homebrew/

Confirm echo $HOME/.nvm returns
/Users/{your username}/.nvm

Now let’s edit zshrc to add nvm bash_completion

vi ~/.zshrc

Add the following lines to the top of the file

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

autoload -Uz compinit
compinit

Note: Make sure you add this snippet before any call to compdef else you will still see the error

Reload the terminal and the errors should be gone

1 Comment

  1. Alfredo says:

    In my case I had to edit my ‘.zshrc’ file. The final lines were:

    # Load Angular CLI autocompletion.
    source https://unix.stackexchange.com/questions/339954/zsh-command-not-found-compinstall-compinit-compdef

    Hope helps.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s