Installing packages locally rather than globally (npx)

I used to install packages globally (npm i -g truffle anyone?) but have now moved to installing locally as I often need different versions between projects.

I recently came across npx (I am new to the JavaScript world, sorry if this is really old news).
npx is a npm package runner which is installed along with npm.

This allows me to run local packages easily and even run packages I haven’t installed.

I also did a check of what I had installed globally.
npm list -g --depth 0
I then uninstalled everything I didn’t absolutely need globally, which was pretty much everything.

Would appreciate thoughts on local vs global.


:heart: being able to run packages without installing

npx cowsay OpenZeppelin

1 Like

Installing globally may cause issues when different projects require different versions, configurations, etc., and makes the whole project environment harder to reproduce (because it assumes global state). The only benefit is not having to type npx, so local installation is a big win for me.


Running things locally is the future. Python has virtualenv for years now and it solves a lot of issues.

1 Like

I suggest checking what you have installed globally:
npm list -g --depth 0

For me ganache-cli is installed globally as I use the one instance in lots of projects, whilst everything else is local.

$ npm list -g --depth 0
├── ganache-cli@6.5.1
└── npm@6.10.3
1 Like