Joji
Joji

Reputation: 5646

after I `npm install -g` something, I cannot use the CLI commands from the installed package

my npm install -g is not working as intended. It installs the package I need, however the CLI commands which comes from the package is always absent.

One example is, I was following the quick start on TypeORM.

It says

First, install TypeORM globally:

npm install typeorm -g

Then go to the directory where you want to create a new project and run the command:

typeorm init --name MyProject --database mysql

but when I tried typeorm init --name MyProject --database mysql. I got the error -bash: typeorm: command not found I think it has something to do with my environment path setting.

This is the output from my echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/aria2/bin:/Applications/Wireshark.app/Contents/MacOS:/Applications/Postgres.app/Contents/Versions/latest/bin

Can someone help me with this?


OK I figured this out myself. Solution is here : https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Upvotes: 3

Views: 1893

Answers (4)

user12942859
user12942859

Reputation: 23

I think im a bit late but it might help someone :D

sudo npm install typeorm -g --unsafe-perm

Upvotes: 1

Javlonbek Sharipov
Javlonbek Sharipov

Reputation: 151

You can use node version manager (nvm). But first uninstall your node.js. Install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Then

command -v nvm

Then exit and open your terminal. Then you can install any version of node.js. For install the latest version type:

nvm install node

When the installation is complete install your package:

npm install typeorm -g

Then it should work correctly.

Upvotes: 1

TheCondorIV
TheCondorIV

Reputation: 614

In Linux/Unix, if you are a normal user, i.e. not root, you cannot install global packages, as these packages are written to system folders. In your case, -g is doing nothing as it cannot access system folders, so it is installed locally as any other regular package. in order to fix your problem, you have to gain more privileges. To do so, you can run the command at the root level i.e:

sudo npm install typeorm -g

and then you can access it from anywhere as -g is intended to put it as global; no need to play with environment path settings as -g also take care of doing so.

if you need a bash session as full root (a root terminal, or in windows terms a cmd/powershell running as administrator) without really signing in to root account for security purpose, use:

sudo -i

and then do whatever you want as root without writing sudo everytime :D; as i said, this command opens the current terminal session as root, so you have to write it in each new opened terminal. Hope it helps :D (It wiill actually ;))

Upvotes: 4

Arshad
Arshad

Reputation: 218

To install package binary globally, npm needs to create links to /usr/local/bin, which may not happen if you don't give it permission. Try running with sudo.

$ sudo npm install typeorm -g

You can run

$ which typeorm

To check if it's installed properly.

Upvotes: 1

Related Questions