user6686227
user6686227

Reputation:

Ubuntu 16 doesn't recognize ng commands

The program 'ng' is currently not installed. You can install it by typing: sudo apt install ng-common

I got no erros during installation, how can i fix this?

Edit: this happens when i try to run ng new PROJECT_NAME

Upvotes: 26

Views: 36534

Answers (18)

Reza Taba
Reza Taba

Reputation: 1904

If you installed Angular CLI using YARN, you must do it globally. Otherwise you get this error. So the fix is:

sudo yarn global add @angular/cli

Then check your Angular version by

ng --version

Linux PopOS (Debian/Ubuntu)

Upvotes: 0

Dhananjay Kumar
Dhananjay Kumar

Reputation: 1

Use this command. It will work perfectly.

sudo npm install --unsafe-perm -g @angular/cli

Upvotes: 0

You have the wrong package:

Just

sudo apt remove ng-common

and

npm install -g @angular-cli

Restart your PC or Terminal

Upvotes: -2

Hamidreza
Hamidreza

Reputation: 1677

By running this command:

npm bin -g

you can see where the npm installs packages globally, including the angular/cli. When you run this command you'll probably see something like this in the output:

/some/directory/bin
(not in PATH env variable)

If so, as you can see in the parentheses, it's saying that this directory is not in PATH env! So what you need to do is to either change this directory to another directory (which is in the PATH env, e.g usr/bin) by npm config set prefix command:

npm config set prefix '/usr'

or to add this directory to the PATH env, by any way you know! But to do so for example you can add this line of code to the ~/.profile file:

export PATH=/some/directory/bin:$PATH

and then restart your computer.

Upvotes: 2

Sandun Susantha
Sandun Susantha

Reputation: 1140

This command worked fine for my issue. press ctrl+T. Then run the following command.

Before that make sure you have installed node js in your local machine. for the verification, you have already installed node js, run the following command on your terminal.

node --version

enter image description here

Then install ng packages by running following commands on your terminal.

npm install -g @angular/cli@latest

enter image description here

npm link @angular/cli

enter image description here Then it will work fine. for the verification of work, fine run any ng command. for example, run on the terminal following command.

ng --version

enter image description here

Upvotes: 4

raikumardipak
raikumardipak

Reputation: 1585

If nothing works, try out this simple step mentioned at https://github.com/angular/angular-cli/issues/10728 bu 'Jikaworld'. Then try the remianing commands for installing angular. It should work.

sudo npm install -g @angular/cli --unsafe-perm=true --allow-root

Upvotes: 0

Robert Moskal
Robert Moskal

Reputation: 22553

That's not how you install the angular command-line tools. You need to use npm to install them globally:

npm install -g @angular/cli

If you want to install a particular version then use

npm install -g @angular/cli@x 

(where x is version number for example. npm install -g @angular/cli@7)

Upvotes: 7

JpG
JpG

Reputation: 932

first in whichever directory you are in come back to home directory

ie prashanth:~/Projects/angular2$ cd ----> prashanth:~$

then enter the following commands

npm bin -g
outputs---> /usr/bin

next,

sudo npm rm -g @angular/cli

clear npm cache,

npm cache clear

then install angular-cli globally,

sudo npm install -g @angular/cli

now you r good to go, type

ng -v

and check the version installed.

Upvotes: 19

Sunny Firodiya
Sunny Firodiya

Reputation: 61

To install it globally, Just run

npm install -g @angular/cli

After that run this command

npm link @angular/cli

and it should work seamlessly and If still not works

restart your system


Upvotes: 6

santhosh-natarajan
santhosh-natarajan

Reputation: 468

It works for me The problem like Refuse to delete old ng file means rename the ng file using mv target file new_file_name and installlsudo npm install --unsafe-perm -g @angular/cli.

click here to source

Upvotes: 0

Dhruv
Dhruv

Reputation: 387

The issue is not specific to Ubuntu version.

Edit (26 Aug, 2018):

Run npm list -g --depth=0 and see if @angular/[email protected] is present in the results.

If it isn't, then you've probably installed angular in local scope.

Install it in global scope with Robert's method mentioned here.


If it still doesn't fix the issue, then reinstall angular completely:

  • npm uninstall -g @angular/cli
  • npm cache clear --force
  • npm install -g @angular/cli

  • Replace @angular/cli with angular-cli if you've installed an older version of angular.

If you have installed node by any other method, follow Edgar's method above.

Upvotes: 11

Sijeesh
Sijeesh

Reputation: 337

Below steps solved my issue,

  1. Upgrade npm to latest

    npm install -g npm@latest

2 Remove angular-cli if already exists

npm remove -g angular-cli

  1. Clear cache

    npm cache clean

    For latest version of npm you don't have to do this. It will correct itself. You can verify using ,

    npm cache verify

4 Install angular/cli again

npm install -g angular-cli

Upvotes: 0

Shubham Kandiyal
Shubham Kandiyal

Reputation: 340

There is no error in node_modules permission

Actually angular 2 is updated to @angular/cli from angular/cli

If you mistakenly install angular 2 using

npm install -g angular-cli

then run

  1. npm install -g @angular-cli

and then

  1. npm install -g @angular-cli/latest

Thanks

Upvotes: 0

Lone Ronin
Lone Ronin

Reputation: 2880

I had the same problem because I downloaded and installed nodejs from the tar.gz package. I did the following to solve the problem:

  1. Deleted the nodejs folder (mine was in Downloads)
  2. Deleted npm and node from my path by removing then from ~/.profile
  3. Install nvm as explained here
  4. Install npm using sudo apt install npm. then upgrae using npm install -g npm@latest
  5. Updgrade node to lates using nvm install --lts
  6. Run npm install -g @angular/cli.

This should fix the problem. If you are still unable to use ng, then check your environmental variables to make sure it has been correctly set.

Upvotes: 2

Pablo Ezequiel Inchausti
Pablo Ezequiel Inchausti

Reputation: 20533

The official Angular-cli documentation say that the installation command is:

$ npm install -g @angular/cli

Again, in the official github repo, installation section is the same command

I had the same problem on ubuntu 16, and after run with sudo, the npm install in that way, everithing goes ok

Upvotes: 0

Tiago Bértolo
Tiago Bértolo

Reputation: 4343

As said here by manuelfink it is a memory issue. Installation needs at least 1GB ram.

Do not forget to run npm cache clean between every attempt.

Upvotes: 0

Siddharth
Siddharth

Reputation: 368

It looks like you have the ng-common package installed on your system, which also provides the ng executable:

http://packages.ubuntu.com/xenial/all/ng-common/filelist

If you are not using ng-common then remove it using sudo apt remove ng-common

then remove node cache

and give a path to in .bashrc or .profile

alias='path/to/node_modules/angular-cli/bin/ng'

Upvotes: -1

AVKurov
AVKurov

Reputation: 154

As it says here and here it might be a memory issue. After I increased RAM from 1024 to 2048 the error gone.

Upvotes: 0

Related Questions