'I can't run ganache in my terminal, even though it's installed

It seems I have a path error, I can see proof the package installed, and I've tried it both globally and local, tried both with and w/o the -cli suffix, but zshell keeps complaining command not found

dr_frankenmiller@Bryans-MacBook-Pro ~ % npm install ganache-cli

npm WARN deprecated [email protected]: ganache-cli is now ganache; visit https://trfl.io/g7 for details

added 1 package, and audited 102 packages in 11s

2 packages are looking for funding
run npm fund for details

9 vulnerabilities (8 moderate, 1 high)

To address issues that do not require attention, run:
npm audit fix

To address all issues (including breaking changes), run:
npm audit fix --force

Run npm audit for details.

dr_frankenmiller@Bryans-MacBook-Pro ~ % npm  ls --depth=0      
dr_frankenmiller@ /Users/dr_frankenmiller
└── [email protected]

dr_frankenmiller@Bryans-MacBook-Pro ~ % ganache-cli

zsh: command not found: ganache-cli

I might have done something bad, using a sudo rm -rf node_modules command to uninstall the package, was that dangerous to do? I reinstalled it globally and then tried running it again, and then zshell started complaining I wasn't authorized to run ganache. I tried the command sudo ganache, it asked me for password, and then responded again that command not found.

Can someone help me get back on track with my tutorial?



Solution 1:[1]

According to Ganache-CLI's instructions, it should be installed with:

npm install ganache-cli -g

I'd recommend installing the latest Ganache version rather than installing Ganache-CLI, though. Ganache-CLI is deprecated. Use

npm uninstall ganache-cli && npm install ganache -g

Ganache v7.0.0 and onward can be used in the CLI as well as programatically.

On another note, I strongly recommend against using sudo when installing anything via npm. This can give untrusted code the ability to run as admin on your system. Definitely a big security risk.

Solution 2:[2]

Just a follow up on difficulties I was having, I ended up using yarn to download and run ganache (MINUS the -cli suffix, -cli suffix now deprecated), yarn install ganache --global to install and then yarn ganache to run (no -cli necessary)

Solution 3:[3]

Here's how I found the solution for my specific use case. The bug came about when I was attempting to run a brownie deployment script. Run npm uninstall ganache-cli then run yarn global add ganache. Worked like a charm.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Micaiah Reid
Solution 2 Bryan Allen
Solution 3