Angular Installation 'ng' command not found

I’ve installed angular cli using the command

npm install -g @angular/cli
It was successful with two warnings. But I’m unable to use
ng
command in console. I’m getting command-not-found response. Please guide.

I was able to install nodejs differently, but arrived at a known issue (with published workaround). I didn’t investigate further after arriving at the known issue, you’ll have to take it from there.

Initial installation

  1. As always, before I install soemthing major in openSUSE, I always run a system update
zypper up
  1. Install nodejs from openSUSE repo
zypper in nodejs4
  1. Install angular/cli. Note that I used the forward slash instead of a hyphen, using a hyphen failed for me.
npm install -g @angular/cli
  1. Now, when I run “ng --help” I get the following published error with some current workaround suggestions

https://github.com/angular/angular-cli/issues/1946

You may wish to try installing a nodejs from the official nedejs repos, if you want to try this I recommend using nodeenv. If you’ve used Python’s virtualenv or Ruby’s rbenv, they’re more or less similar… You can download and run different nodejs versions side by side, and specify which you want to use globally or for specific application file trees.

http://ekalinin.github.io/nodeenv/

HTH,
TSU

Remember and consider also that angular-cli is still currently in Beta.
Problems like what I arrived at can probably be expected, particularly if you follow the overall history of Angular.

TSU

Many Thanks! Still it’s not working. As you said this is an inherent issue.

I found out the solution to the issue by symlinking ng from /opt folder.
Please follow the instructions:

sudo ln -s /opt/node-v7.8.0-linux-x64/node_modules/@angular/cli/bin/ng /usr/bin/ng

Hm, that works of course, but wouldn’t a better solution be to put /opt/node-v7.8.0-linux-x64/node_modules/@angular/cli/bin/ in the user’s PATH?

I don’t know. Could you please guide me?

Hi,

Here is an example

Check the value of your “$PATH”

echo "$PATH"

Create a directory first in your “$HOME” and add it to your PATH.

mkdir "$HOME/Scripts"

now add the new directory in your PATH

PATH+=:$HOME/Scripts

Check the value of your “$PATH” after you have done the above code.

echo "$PATH"

That should give you the additional path.

To test it, create a script inside that directory and make it executable.

printf '%s
' '#!/usr/bin/env bash' 'echo "Hello World!"' > "$HOME"/Scripts/hello

chmod +x “$HOME”/Scripts/hello



Check what is inside that hello file.


cat “$HOME/Scripts/hello”




#!/usr/bin/env bash
echo “Hello World!”



Now to check if you have an executable named hello in your PATH. Note that key in the complete code and not just hello.

type hello



file “$HOME/Scripts/hello”


Now run that hello script.

hello


the output should be.

Hello World!



To make that change permanent the run code below. That code will put **PATH+=:$HOME/Scripts** into the **last line **of your ~/.bashrc. Note that use the double **>>** instead of a single** >**. But just in case you made a mistake the ~/.bashrc file is located in **/etc/skel
**


echo PATH+=:$HOME/Scripts >> ~/.bashrc

In you case replace the Scripts directory with the absolute PATH of the directory you that you want to add in your user’s PATH. This is all assuming that you’re default login shell is still the default in openSUSE which is bash.

Hi,

Sorry the last part of the post was messed up. Here is the correct way to add it to your PATH.

if  :$PATH: != *:$HOME/Scripts:* ]]; then
  PATH+=:$HOME/Scripts
fi    

Put that code inside your ~/.bashrc. Without the test every time you exec bash the pat gets added again and again :).
you can see for your self by running

exec bash

with the previous code and this one.

In your case it would be

if  :$PATH: != *:/opt/node-v7.8.0-linux-x64/node_modules/@angular/cli/bin/:* ]]; then
     PATH+=':/opt/node-v7.8.0-linux-x64/node_modules/@angular/cli/bin/'
fi

Wouldn’t the following have been simpler to add the directory to the system PATH?
Note that the following will then apply to all User/system security context, not just the logged in User (which would be the case if you modify the User PATH instead of the system PATH)

Following is written in a way that might be used in a script (add line concatenations), but of course can be done manually with vi or other text editor

#Following creates profile.local file because direct edits to /etc/profile are lost with an upgrade
touch /etc/profile.local
#Following appends new directory to system PATH
cat /etc/profile.local << "export PATH=$PATH:/opt/node-v7.8.0-linux-x64/node_modules/@angular/cli/bin/ng"
# Following activates and updates /etc/profile without a reboot
source /etc/profile

TSU