21
votes

I installed truffle through npm with the following:

sudo npm install -g truffle

but when I run truffle list on the console it just gives me

bash: truffle: command not found

12
What OS is that, Ubuntu 16.4? - Afr

12 Answers

24
votes

I had a similar problem. I ran npm i -g truffle and then when I tried to run truffle init I got an error: zsh: command not found: truffle. What solved it for me is to create a local node_modules with truffle installed in it, and then run that copy.

  1. run npm init and make a new npm project
  2. run npm i truffle
  3. run ./node_modules/.bin/truffle init and it should work!
18
votes

Please make sure you have the latest version of npm and node installed. I had the same issue, I updated npm and node to latest version and it worked.

npm install -g truffle works.

4
votes

I did it on a Virtual box and had the same issue, but it worked after I restarted the computer. Hopefully that works for you too

4
votes

After installing truffle:

npm install -g truffle

Run on your project folder:

npx truffle init

2
votes

I tried everything. Followed the instruction on official truffle website and above answers. Still it didn't seem to worked.

Finally, this worked for me. Go to C:\Users\Username\AppData\Roaming\npm

There you will find truffle.cmd Double click on it and your done.

2
votes

npm i truffle does the exact same thing as npm install -g truffle except that installs it globally, and without -g it will be installed on the local folder. Try to update the npm, node, and probably you have a broken node installation from previous versions.

2
votes

You should add the following to your path system variable.

C:\Users\UserName\AppData\Roaming\npm

(This folder contains the truffle.cmd file)

I have tried and it works.

1
votes

Using npm install -g truffle worked for me instead of npm i truffle

1
votes

Nothing above worked for me, but I did:

  1. nix truffle unbox react
  2. truffle develop
  3. atom . //opens up the react file project in the atom platform
1
votes

You should add C:\Users\UserName\AppData\Roaming\npm (it contains truffle.cmd file) to the path user variables. I have tried and it works

1
votes

If you have a custom path for your packages, then make sure that you are exporting it when the terminal loads.

For bash:

nano ~/.profile

For zsh:

nano ~./zshrc

And add your custom path, most of the time this will be "npm-global".

export PATH=~/.npm-global/bin:$PATH
0
votes

1-- run npm init and make a new npm project 2-- run npm i truffle 3-- run ./node_modules/.bin/truffle init

I'm sure, this will help you. :)