How to Fix 'command not found' Error After npm install --global in asdf Environment
I’ll share about solving a command not found error that occurred when trying to use a command-line tool after installing it globally with npm
in an environment where Node.js version is managed using asdf.
npm install --global
(npm install -g
)For example, to install Anthropic’s Claude command-line tool, I executed the following command:
npm install -g @anthropic-ai/claude-code
The installation appeared to complete normally. However, when I actually tried to run the claude
command:
claude
zsh: command not found: claude
The shell couldn’t find the command and resulted in an error.
When command not found appears after running npm install -g
in an asdf environment, the cause lies in the mechanism asdf uses to manage commands.
asdf doesn’t directly add paths to executable files of each installed language, but executes commands through wrapper scripts called shims. This enables automatic switching to the appropriate version of commands for each project.
Even after installing a new command (in this example, claude
) with npm install -g
, asdf doesn’t automatically recognize its existence. Therefore, the new command isn’t added to asdf’s managed shim list, resulting in a state where the path is not available.
asdf reshim
In conclusion, running asdf reshim
will solve the problem.
reshim
is a command that instructs asdf to rescan installed packages and regenerate shims.
In this case, since we installed a Node.js package, we run the following command:
asdf reshim nodejs
By running this command, asdf will recognize the newly installed claude
command and create the appropriate shim.
After running the command, try the claude
command again. It should now execute normally.
By developing a habit of running the corresponding language’s asdf reshim
after globally installing packages in an asdf environment, you can prevent such command not found errors.
npm install -g
.asdf reshim <target>
. (Example: asdf reshim nodejs
)If you encounter a similar phenomenon, please try this solution.
That’s all from the Gemba.