29

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

Seanny123
  • 8,776
  • 13
  • 68
  • 124
user3480478
  • 429
  • 1
  • 4
  • 5

14 Answers14

33

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!
drussell
  • 509
  • 4
  • 5
22

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.

druuu
  • 1,676
  • 6
  • 19
  • 36
9

After installing truffle:

npm install -g truffle

Run on your project folder:

npx truffle init

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
aadry_17
  • 99
  • 1
  • 1
  • I installed truffle in my local project - 'npm install truffle' ...then when I tried to run 'truffle init', I got the error 'zsh: command not found: truffle'.... I upgraded to a more recent version of Node & same error.... Running 'npx truffle init' worked like a charm!!! – Frankie Dec 22 '21 at 22:50
  • did not work for me – insivika Dec 24 '21 at 16:18
6

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

thefett
  • 280
  • 2
  • 8
3

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.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Khan Javed
  • 31
  • 1
2

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

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.

1

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

1

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
Adambomb1
  • 11
  • 1
1

Try to start with your command like

npx truffle <your command>
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 03 '21 at 10:35
0

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

0

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
Samuel
  • 37
  • 3
0

These are two simple steps the properly solve this problem for Linux Users:

1- Configure npm to install software globally in your home directory as follows :

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

2- If you are using bash, then execute the following:

echo -n "export PATH=~/.npm-global/bin:$PATH" >> ~/.profile 

However, if you are using zsh instead, then execute the following command:

echo -n "export PATH=~/.npm-global/bin:$PATH" >> ~/.zshrc 

Note that, if you are using both bash and zsh, it is better to execute the two commands above.

liedji
  • 739
  • 10
  • 11
0

I solved this problem by doing the following commands:-

  1. npm uninstall -g truffle

  2. sudo npm install -g truffle Be aware when using sudo(root)

Then it works when I use the below command

truffle init in my dir. Basically it will bootstrap

Narendranath Reddy
  • 3,833
  • 3
  • 13
  • 32
shaun Ko
  • 21
  • 4