코드코코

[리눅스] ubuntu에 nodejs 설치하기 본문

기록/리눅스

[리눅스] ubuntu에 nodejs 설치하기

코드코코 2021. 12. 13. 20:31

1. nvm (Node Version Manager) 설치

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

root@DESKTOP-RJ31OF5:/home/ubuntu# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh|bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14926  100 14926    0     0  61677      0 --:--:-- --:--:-- --:--:-- 61423
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
remote: Enumerating objects: 349, done.
remote: Counting objects: 100% (349/349), done.
remote: Compressing objects: 100% (297/297), done.
remote: Total 349 (delta 39), reused 165 (delta 27), pack-reused 0
Receiving objects: 100% (349/349), 202.48 KiB | 3.27 MiB/s, done.
Resolving deltas: 100% (39/39), done.
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
root@DESKTOP-RJ31OF5:/home/ubuntu#

2. nvm 활성화

. ~/.nvm/nvm.sh

 

root@DESKTOP-RJ31OF5:/home/ubuntu# . ~/.nvm/nvm.sh

3. Node.js 설치

nvm install node

 

root@DESKTOP-RJ31OF5:/home/ubuntu# nvm install node
Downloading and installing node v17.2.0...
Downloading https://nodejs.org/dist/v17.2.0/node-v17.2.0-linux-x64.tar.xz...
################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v17.2.0 (npm v8.1.4)
Creating default alias: default -> node (-> v17.2.0)
root@DESKTOP-RJ31OF5:/home/ubuntu#

4. Node.js 및 npm 설치 확인

node -v

npm -v

root@DESKTOP-RJ31OF5:/home/ubuntu# node -v
v17.2.0
root@DESKTOP-RJ31OF5:/home/ubuntu# npm -v
8.1.4
root@DESKTOP-RJ31OF5:/home/ubuntu#

 

5. npm 버전 업그레이드가 필요한 경우

npm install -g npm@8.3.0

root@DESKTOP-RJ31OF5:/home/ubuntu/server# npm install -g npm@8.3.0

removed 8 packages, changed 20 packages, and audited 215 packages in 6s

10 packages are looking for funding
  run `npm fund` for details

3 moderate severity vulnerabilities

To address all issues, run:
  npm audit fix

Run `npm audit` for details.