Results 1 to 10 of 10

Thread: Angular Installation 'ng' command not found

  1. #1
    Join Date
    May 2016
    Location
    Chennai, TN, India
    Posts
    76

    Default 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.

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,256
    Blog Entries
    2

    Default Re: Angular Installation 'ng' command not found

    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
    Code:
    zypper up
    2. Install nodejs from openSUSE repo
    Code:
    zypper in nodejs4
    3. Install angular/cli. Note that I used the forward slash instead of a hyphen, using a hyphen failed for me.
    Code:
    npm install -g @angular/cli
    4. 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
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,256
    Blog Entries
    2

    Default Re: Angular Installation 'ng' command not found

    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
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  4. #4
    Join Date
    May 2016
    Location
    Chennai, TN, India
    Posts
    76

    Default Re: Angular Installation 'ng' command not found

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

  5. #5
    Join Date
    May 2016
    Location
    Chennai, TN, India
    Posts
    76

    Default Re: Angular Installation 'ng' command not found

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

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

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,117

    Default Re: Angular Installation 'ng' command not found

    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?
    Henk van Velden

  7. #7
    Join Date
    May 2016
    Location
    Chennai, TN, India
    Posts
    76

    Default Re: Angular Installation 'ng' command not found

    Quote Originally Posted by hcvv View Post
    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?

  8. #8

    Default Re: Angular Installation 'ng' command not found

    Quote Originally Posted by linlen View Post
    I don't know. Could you please guide me?
    Hi,

    Here is an example

    Check the value of your "$PATH"
    Code:
    echo "$PATH"
    Create a directory first in your "$HOME" and add it to your PATH.

    Code:
    mkdir "$HOME/Scripts"
    now add the new directory in your PATH

    Code:
    PATH+=:$HOME/Scripts
    Check the value of your "$PATH" after you have done the above code.
    Code:
    echo "$PATH"
    That should give you the additional path.

    To test it, create a script inside that directory and make it executable.
    Code:
    printf '%s\n' '#!/usr/bin/env bash' 'echo "Hello World!"' > "$HOME"/Scripts/hello
    
    Code:
    chmod +x "$HOME"/Scripts/hello
    Check what is inside that hello file.
    Code:
    cat "$HOME/Scripts/hello"
    Code:
    #!/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.
    Code:
    type hello
    Code:
    file "$HOME/Scripts/hello"
    Now run that hello script.
    Code:
    hello
    the output should be.
    Code:
    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
    Code:
    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.
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  9. #9

    Default Re: Angular Installation 'ng' command not found

    Hi,

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

    Code:
    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

    Code:
    exec bash
    with the previous code and this one.

    In your case it would be
    Code:
    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
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  10. #10
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,256
    Blog Entries
    2

    Default Re: Angular Installation 'ng' command not found

    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
    Code:
    #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
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •