Ubuntu how to run ng commnd

In Ubuntu 16.04, I have installed nodejs with the following command:

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

To confirm, I used the command which nodejs and it returns

/usr/bin/nodejs

I want to run an Angular project. I have also created 'node_modules' folder and updated the 'Angular CLI'. However, the ng command is not working in terminal.

Edited

Below is my package.json content:

{
  "name": "angular",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/core": "^0.2.0",
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.7",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

The Blank terminal is given in below screen:

enter image description here

I see after running the command npm install -g @angular/cli the below error comes:

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib' npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib'] npm ERR! errno: -13, npm ERR!
code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/local/lib' } npm ERR! npm ERR! Please try running this command again as root/Administrator.

EDITED 2


Now I see after placing ng serve command:

niladri@niladrib:/var/www/html/ngAngular$ ng serve /usr/local/lib/node_modules/@angular/cli/models/config/config.js:17 constructor(_configPath, schema, configJson, fallbacks = []) { ^

SyntaxError: Unexpected token = at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object. (/usr/local/lib/node_modules/@angular/cli/models/config.js:3:18) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10)

Upvotes: 0

Views: 5920

Answers (5)

Shivangi
Shivangi

Reputation: 3062

Angular-cli has certain prerequisites, which includes node version > 6.9, as can be seen here:

https://github.com/angular/angular-cli#prerequisites

To update node to latest version, we can follow :

https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

Upvotes: 1

Carlos vm
Carlos vm

Reputation: 21

hey @Shivi first install npm install -g sass node-sass. this in a global way. then enter the ngAngular folder in install the dependencies with "npm install" and this will be enough after ng serve to run the project. an image that if it runs enter image description here

Upvotes: 0

nipuna-g
nipuna-g

Reputation: 6652

You need to install AngularCLI globally in order to serve up the application using ng serve.

To do this run the following command in your terminal:
npm install -g @angular/cli (use sudo if you need administrator privileges on Ubuntu.)

This will install AngularCLI globally. Which you can then simply used to serve the application by navigating to the folder and typing ng s.

Upvotes: 1

Carlos vm
Carlos vm

Reputation: 21

ok, first write to your terminal ng --version, with this you will get the version of angular cli that you have installed on your desktop and compare it with this "@ angular / cli": "^ 1.6.7" if the version of your angular cli at the bottom, update it, the how to do it is in the documentation, after that write in the terminal sudo npm install, so that all the dependencies of the Json package file are installed after running ng serve

Upvotes: 0

Carlos vm
Carlos vm

Reputation: 21

check the json package file, look at the script section, write the text after start in your terminal. example in that same file you can see the installed dependencies in the folder node_modules

Upvotes: 0

Related Questions