スキップしてメイン コンテンツに移動

Install Node.js and Angular on Ubuntu

What I did

  1. Install Node.js
  2. Install Angular
  3. Try default app

Install Node.js

Few years ago, when I had used Ubuntu, I used nodebrew to install Node.js.
But now, what shall I use?

Use n

My search result was I should use n.
But the easiest way to install n had needed npm.
npm install -g n
So I installed Node.js by NodeSource first.
Installing Node.js via package manager | Node.js
distributions/README.md at master · nodesource/distributions · GitHub
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs
I installed Node.js version 13.9.0.

Failed npm -g install

After installing Node.js, I had tried install n and failed with permission error.
example@example-Macmini:~$ npm install -g n
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/lib/node_modules'] {
npm ERR!   stack: "Error: EACCES: permission denied, access '/usr/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/example/.npm/_logs/2020-02-23T12_38_49_814Z-debug.log
Although someone installed with super user, according to the documents of npm, I changed the npm global install directory.
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Resolving EACCES permissions errors when installing packages globally | npm Documentation

Install Angular

Now I had been able to install globally, I just installed Angular CLI.
And I tried create the sample project.
npm install -g @angular/cli

Command 'ng' not found

When I had created an Angular project, I got error.
Command 'ng' not found, but can be installed with:
sudo apt install ng-common
So I added an alias of ng.
echo "alias ng=~/.npm-global/bin/ng" >> ~/.bashrc
source ~/.bashrc
After all, I could create the Angular project.
And the hot reload also worked.

コメント