AWS EC2の「Ubuntu Server」インスタンス上でNode.jsとnpmをインストールする
AWS EC2の「Ubuntu Server」インスタンス上でNode.jsとnpmをインストールしてみます。
この記事は「AWS EC2の「Ubuntu Server」インスタンス上でインストールされている Node.js の バージョンを確認する」の続きでもあります。
■PC環境
Windows10(Google Chrome)
AWS インスタンス作成済み(Ubuntu 22.04 LTS (GNU/Linux 5.15.0-1011-aws x86 64))
■SSHクライアント「PuTTY」を用いてSSHで接続する
今回Node.jsとnpmのインストールを行いますが、その前に「AWS マネジメントコンソール」にログインし、「EC2」サービスへ移動します。移動後、「EC2 Management Console」内の左メニューの「インスタンス」の「インスタンス」をクリックすると、作成した「インスタンス」が一覧で表示されます。
今回作成した「Ubuntu Server」インスタンスの「インスタンス状態」が「実行中」であることを確認します。確認後、SSHクライアント「PuTTY」を用いて、SSHで接続を行います。
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-1011-aws x86 64)
- Documentation: https://help.ub
- Management: https://landscape.canonical.com
- Support: https://ubuntu.com/advantage
System information as of Fri Jul 8 00:49:50 UTC 2022
System load: 0.0 Usage of 7: 22.6% of 7.58GB Memory usage: 234 Swap usage: 0%
Processes:
100 Users logged in: IPv4 address for etho: *...
- Ubuntu Pro delivers the most comprehensive open source security and,
compliance features.
https://ubuntu.com/aws/pro
42 updates can be applied immediately.
22 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
SSHで接続すると、上記のようなメッセージが出力されます。
ubuntu@ip-**-**-**-**(ipアドレス):~$
出力後、上記のように出力されれば、接続は完了となります。
■Node.jsとnpmをインストールする
$ sudo apt update
接続完了後、上記のコマンドを入力し、Enterキーを押します。sudo権限で「apt」コマンドを用います。「apt」コマンドは、システム内のソフトウェアのインストール、削除、更新を担当し、「update」でリポジトリ内の利用可能なすべてのソフトウェアを読み取り、これらを「Ubuntu 22.04 LTS」インスタンス側にあるバージョンと比較して、最新のものに更新します。Enterキーを押すと、更新が行われ、完了となります。
$ sudo apt install nodejs npm
完了後、上記のコマンドを入力し、Enterキーを押します。sudo権限で「apt」コマンドを用います。これでNode.jsとnpmのインストールを行います。
Reading package lists... DoneBuilding dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
build-essential bzip2 dpkg-dev fakeroot g++ g++-11 gcc gcc-11 gyp
javascript-common libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libasan6 libatomic1 libc-ares2 libc-dev-bin
libc-devtools libc6-dev libcc1-0 libcrypt-dev libdpkg-perl libfakeroot
libfile-fcntllock-perl libgcc-11-dev libgd3 libgomp1 libitm1 libjs-events
libjs-highlight.js libjs-inherits libjs-is-typedarray libjs-psl
libjs-source-map libjs-sprintf-js libjs-typedarray-to-buffer liblsan0
libnode-dev libnode72 libnotify-bin libnotify4 libnsl-dev libquadmath0
libssl-dev libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 libuv1-dev
linux-libc-dev lto-disabled-list make manpages-dev node-abab node-abbrev
node-agent-base node-ansi-regex node-ansi-styles node-ansistyles node-aproba
node-archy node-are-we-there-yet node-argparse node-arrify node-asap
node-asynckit node-balanced-match node-brace-expansion node-builtins
node-cacache node-chalk node-chownr node-clean-yaml-object node-cli-table
node-clone node-color-convert node-color-name node-colors node-columnify
node-combined-stream node-commander node-console-control-strings
node-copy-concurrently node-core-util-is node-coveralls node-cssom
node-cssstyle node-debug node-decompress-response node-defaults
node-delayed-stream node-delegates node-depd node-diff node-encoding
node-end-of-stream node-err-code node-escape-string-regexp node-esprima
node-events node-fancy-log node-fetch node-foreground-child node-form-data
node-fs-write-stream-atomic node-fs.realpath node-function-bind node-gauge
node-get-stream node-glob node-got node-graceful-fs node-growl node-gyp
node-has-flag node-has-unicode node-hosted-git-info node-https-proxy-agent
node-iconv-lite node-iferr node-imurmurhash node-indent-string node-inflight
node-inherits node-ini node-ip node-ip-regex node-is-buffer
node-is-plain-obj node-is-typedarray node-isarray node-isexe node-js-yaml
node-jsdom node-json-buffer node-json-parse-better-errors node-jsonparse
node-kind-of node-lcov-parse node-lodash-packages node-log-driver
node-lowercase-keys node-lru-cache node-mime node-mime-types
node-mimic-response node-minimatch node-minimist node-minipass node-mkdirp
node-move-concurrently node-ms node-mute-stream node-negotiator node-nopt
node-normalize-package-data node-npm-bundled node-npm-package-arg
node-npmlog node-object-assign node-once node-opener node-osenv
node-p-cancelable node-p-map node-path-is-absolute node-process-nextick-args
node-promise-inflight node-promise-retry node-promzard node-psl node-pump
node-punycode node-quick-lru node-read node-read-package-json
node-readable-stream node-resolve node-retry node-rimraf node-run-queue
node-safe-buffer node-semver node-set-blocking node-signal-exit node-slash
node-slice-ansi node-source-map node-source-map-support node-spdx-correct
node-spdx-exceptions node-spdx-expression-parse node-spdx-license-ids
node-sprintf-js node-ssri node-stack-utils node-stealthy-require
node-string-decoder node-string-width node-strip-ansi node-supports-color
node-tap node-tap-mocha-reporter node-tap-parser node-tar node-text-table
node-time-stamp node-tmatch node-tough-cookie node-typedarray-to-buffer
node-unique-filename node-universalify node-util-deprecate
node-validate-npm-package-license node-validate-npm-package-name
node-wcwidth.js node-webidl-conversions node-whatwg-fetch node-which
node-wide-align node-wrappy node-write-file-atomic node-ws node-yallist
nodejs-doc rpcsvc-proto
Suggested packages:
bzip2-doc debian-keyring g++-multilib g++-11-multilib gcc-11-doc
gcc-multilib autoconf automake libtool flex bison gdb gcc-doc
gcc-11-multilib gcc-11-locales apache2 | lighttpd | httpd glibc-doc bzr
libgd-tools libjs-angularjs gnome-shell | notification-daemon libssl-doc
libstdc++-11-doc make-doc node-nyc
The following NEW packages will be installed:
build-essential bzip2 dpkg-dev fakeroot g++ g++-11 gcc gcc-11 gyp
javascript-common libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libasan6 libatomic1 libc-ares2 libc-dev-bin
libc-devtools libc6-dev libcc1-0 libcrypt-dev libdpkg-perl libfakeroot
libfile-fcntllock-perl libgcc-11-dev libgd3 libgomp1 libitm1 libjs-events
libjs-highlight.js libjs-inherits libjs-is-typedarray libjs-psl
libjs-source-map libjs-sprintf-js libjs-typedarray-to-buffer liblsan0
libnode-dev libnode72 libnotify-bin libnotify4 libnsl-dev libquadmath0
libssl-dev libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 libuv1-dev
linux-libc-dev lto-disabled-list make manpages-dev node-abab node-abbrev
node-agent-base node-ansi-regex node-ansi-styles node-ansistyles node-aproba
node-archy node-are-we-there-yet node-argparse node-arrify node-asap
node-asynckit node-balanced-match node-brace-expansion node-builtins
node-cacache node-chalk node-chownr node-clean-yaml-object node-cli-table
node-clone node-color-convert node-color-name node-colors node-columnify
node-combined-stream node-commander node-console-control-strings
node-copy-concurrently node-core-util-is node-coveralls node-cssom
node-cssstyle node-debug node-decompress-response node-defaults
node-delayed-stream node-delegates node-depd node-diff node-encoding
node-end-of-stream node-err-code node-escape-string-regexp node-esprima
node-events node-fancy-log node-fetch node-foreground-child node-form-data
node-fs-write-stream-atomic node-fs.realpath node-function-bind node-gauge
node-get-stream node-glob node-got node-graceful-fs node-growl node-gyp
node-has-flag node-has-unicode node-hosted-git-info node-https-proxy-agent
node-iconv-lite node-iferr node-imurmurhash node-indent-string node-inflight
node-inherits node-ini node-ip node-ip-regex node-is-buffer
node-is-plain-obj node-is-typedarray node-isarray node-isexe node-js-yaml
node-jsdom node-json-buffer node-json-parse-better-errors node-jsonparse
node-kind-of node-lcov-parse node-lodash-packages node-log-driver
node-lowercase-keys node-lru-cache node-mime node-mime-types
node-mimic-response node-minimatch node-minimist node-minipass node-mkdirp
node-move-concurrently node-ms node-mute-stream node-negotiator node-nopt
node-normalize-package-data node-npm-bundled node-npm-package-arg
node-npmlog node-object-assign node-once node-opener node-osenv
node-p-cancelable node-p-map node-path-is-absolute node-process-nextick-args
node-promise-inflight node-promise-retry node-promzard node-psl node-pump
node-punycode node-quick-lru node-read node-read-package-json
node-readable-stream node-resolve node-retry node-rimraf node-run-queue
node-safe-buffer node-semver node-set-blocking node-signal-exit node-slash
node-slice-ansi node-source-map node-source-map-support node-spdx-correct
node-spdx-exceptions node-spdx-expression-parse node-spdx-license-ids
node-sprintf-js node-ssri node-stack-utils node-stealthy-require
node-string-decoder node-string-width node-strip-ansi node-supports-color
node-tap node-tap-mocha-reporter node-tap-parser node-tar node-text-table
node-time-stamp node-tmatch node-tough-cookie node-typedarray-to-buffer
node-unique-filename node-universalify node-util-deprecate
node-validate-npm-package-license node-validate-npm-package-name
node-wcwidth.js node-webidl-conversions node-whatwg-fetch node-which
node-wide-align node-wrappy node-write-file-atomic node-ws node-yallist
nodejs nodejs-doc npm rpcsvc-proto
0 upgraded, 228 newly installed, 0 to remove and 19 not upgraded.
Need to get 72.2 MB of archives.
After this operation, 274 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Enterキーを押すと、取得するアーカイブの情報や追加ディスクスペースの容量などが出力され、「Do you want to continue?(続けますか?)」と質問されますので、インストールを進めますので、「Y」と入力し、Enterキーを押します。
Enterキーを押すと、インストールが開始され、しばらくすると完了となります。
■Node.jsとnpmのインストールを確認する
$ nodejs --version
インストール完了後、上記のコマンドを入力し、Enterキーを押します。「nodejs」コマンドを用い、オプションで「--version」と指定します。
v12.22.9
Enterキーを押すと、node.jsのバージョンが出力されました。これで実際にnode.jsがインストールされていることが確認できました。
$ npm --version
次に、npmのバージョンを確認してみます。確認のために、上記のコマンドを入力し、Enterキーを押します。「npm」コマンドを用い、オプションで「--version」と指定します。
8.5.1
Enterキーを押すと、npmのバージョンが出力されました。これで実際にnpmがインストールされていることが確認できました。これでNode.jsとnpmのインストール確認は完了となります。





