Can't install angular-cli on Mac

前端 未结 12 1045
南笙
南笙 2020-12-28 23:33

This is probably very trivial, but I am hitting my head against the wall while I am trying to (unsuccessfully) install angular-cli.

I am following the official angul

相关标签:
12条回答
  • 2020-12-29 00:19

    Steps to install angular cli.

    1. Download Nodejs and Install it. https://nodejs.org/en/
    2. Open terminal and type: sudo npm install -g @angular/cli

    Just remember that -g represents global scope hence package is installing in root level folders. Hence the command should start with "sudo"

    0 讨论(0)
  • 2020-12-29 00:20

    These are the codes I used

    sudo npm uninstall -g angular-cli
    sudo npm uninstall -g @angular/cli
    sudo npm cache clean --force
    npm install -g @angular/cli
    alias ng="~/node_modules/@angular/cli/bin/ng"
    

    for check

    ng --version
    
    0 讨论(0)
  • 2020-12-29 00:21

    After several tries, I finally installed angular-cli successfully via nvm. In detail:

    Install nvm:

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
    export NVM_DIR="/Users/mkotsollaris/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    nvm --version
    0.33.0
    

    Then install node through nvm:

    nvm install stable
    nvm install node
    

    Thereafter, install angular-cli:

    npm install -g @angular/cli
    mkotsolarissMBP:myapp mkotsollaris$ ng -v
    
        _                      _                 ____ _     ___
       / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
      / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
     / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
    /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                   |___/
    
    Angular CLI: 1.6.5
    Node: 9.4.0
    OS: darwin x64
    Angular: 5.2.1
    ... animations, common, compiler, compiler-cli, core, forms
    ... http, language-service, platform-browser
    ... platform-browser-dynamic, router
    
    @angular/cli: 1.6.5
    @angular-devkit/build-optimizer: 0.0.41
    @angular-devkit/core: 0.0.28
    @angular-devkit/schematics: 0.0.51
    @ngtools/json-schema: 1.1.0
    @ngtools/webpack: 1.9.5
    @schematics/angular: 0.1.16
    typescript: 2.5.3
    webpack: 3.10.0
    mkotsolarissMBP:myapp mkotsollaris$ 
    

    Verify that ng works properly:

    ng new my-project
    cd my-project
    ng serve
    

    The app will start on localhost:4200.

    0 讨论(0)
  • 2020-12-29 00:21

    Try this:

    sudo npm install -g @angular/cli 
    
    0 讨论(0)
  • 2020-12-29 00:21

    This seems like a problem with your node/npm and not with Angular CLI.

    Please have a look at the fixing npm permissions page, common errors page, npm issue tracker, or open a new issue if the problem you are experiencing isn't known.

    0 讨论(0)
  • 2020-12-29 00:26

    i faced similar issue while installing angular-cli on Mac Mojave.

    Correct installation steps are:

    1. Install npm using package manager.
    2. above step sets the directory owner of /usr/local/lib/node_modules/ to root.
    3. execute below command to set the owner to your user:
      sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

    4. npm install -g @angular/cli (avoid using sudo)

    0 讨论(0)
提交回复
热议问题