How to Fix 'command not found' Error After npm install --global in asdf Environment

Tadashi Shigeoka ·  Sat, March 22, 2025

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.

Background: Command not found after 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.

Cause: asdf shim is not updated

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.

Solution: Run 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.

Summary

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.

  • Problem: Command not found after npm install -g.
  • Cause: asdf shim is not updated.
  • Solution: Run asdf reshim <target>. (Example: asdf reshim nodejs)

If you encounter a similar phenomenon, please try this solution.

That’s all from the Gemba.