'Trying to run truffle and it says command not found on my mac

I've been trying to start Truffle but when I do $ truffle it says command not found. I've done npm init, npm i truffle and ./node_modules/.bin/truffle init but nothing works. I have the latest version of node but it still makes no difference.

Roberts-MacBook-Pro-9:~ rbeit$ truffle init
-bash: truffle: command not found
Roberts-MacBook-Pro-9:~ rbeit$ truffle
-bash: truffle: command not found
Roberts-MacBook-Pro-9:~ rbeit$


Solution 1:[1]

You have only installed the truffle npm locally, you can ether install it globally with npm install -g truffle or call it from npm by adding

  "scripts": {
    "truffle": "truffle init",
  }

to your package.json

and call it like this npm run truffle

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