Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npx with angular cli, how to install @angular/cli and use it afterwards

Tags:

npm

angular

npx

I just found NPX, this tool lets you install global packages without sudo rights. I want to use it with my angular projects.

I run

dev@b7ee560044f1:~/project$ npx -p @angular/cli ng version
npx: installed 294 in 6.391s

Looks good, it works

But if i retry the same command i will get

dev@b7ee560044f1:~/project$ npx @angular/cli ng version
npx: installed 294 in 4.725s

Why NPX installs angular cli package every time? I thought that downloading package is performed only once and cached somewhere..

I thought that this command would work but it doesn't...

dev@b7ee560044f1:~/project$ npx ng version
npx: installed 1 in 0.98s
command not found: ng
like image 554
Alexander Kondaurov Avatar asked Jan 14 '19 15:01

Alexander Kondaurov


3 Answers

As Bharat already wrote: -p is maybe what you are looking for.

Local (Global) I'm using @angular/[email protected].

But with the following command:

npx -p @angular/cli@8 ng new sample-application --style=scss

I was able to create a new angular project with the latest 8.x version (8.2.14).

like image 101
Crazybutch Avatar answered Nov 03 '22 10:11

Crazybutch


This tool allow you to run commands from the npm registry but the cli is not stored locally.

PD: the alias ng is used to replace the name completely. @angular/cli is the whole name ng is the alias. You should use or run npx @angular/cli (command) like generate for instance would be npx @angular/cli generate component helloworld

like image 34
juanramirezcastaneda Avatar answered Nov 03 '22 11:11

juanramirezcastaneda


npx is ideally used for temporarily installing packages from npm and running them one time so if you want install Angular CLI and continue using it afterward you need to install using the regular npm install command:

$ npm install --global @angular/cli

Also, make sure you use the --global switch so it can be available from any location in your system.

like image 2
Farid Rajab Avatar answered Nov 03 '22 10:11

Farid Rajab