CentOSにnode.jsをインストールする

$ node --version

-bash: node: コマンドが見つかりません

$ curl -sL https://rpm.nodesource.com/setup_8.x | sudo bash -
[sudo] パスワード:

## Installing the NodeSource Node.js 8.x LTS Carbon repo…

## Inspecting system…

+ rpm -q –whatprovides redhat-release || rpm -q –whatprovides centos-release || rpm -q –whatprovides cloudlinux-release || rpm -q –whatprovides sl-release
+ uname -m

## Confirming “el7-x86_64” is supported…

+ curl -sLf -o /dev/null ‘https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm’

## Downloading release setup RPM…

+ mktemp
+ curl -sL -o ‘/tmp/tmp.XOyX3qzAtS’ ‘https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm’

## Installing release setup RPM…

+ rpm -i –nosignature –force ‘/tmp/tmp.XOyX3qzAtS’

## Cleaning up…

+ rm -f ‘/tmp/tmp.XOyX3qzAtS’

## Checking for existing installations…

+ rpm -qa ‘node|npm’ | grep -v nodesource

## Run `sudo yum install -y nodejs` to install Node.js 8.x LTS Carbon and npm.
## You may also need development tools to build native addons:
sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install yarn

[upla@os3-364-15302 ~]$ sudo yum install nodejs
読み込んだプラグイン:fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink | 4.9 kB 00:00
* base: mirrors.cat.net
* epel: ftp.jaist.ac.jp
* extras: ty1.mirror.newmediaexpress.com
* remi-safe: ftp.riken.jp
* updates: ty1.mirror.newmediaexpress.com
base | 3.6 kB 00:00
epel | 5.4 kB 00:00
extras | 2.9 kB 00:00
nodesource | 2.5 kB 00:00
remi-safe | 3.0 kB 00:00
updates | 2.9 kB 00:00
(1/8): extras/7/x86_64/primary_db | 152 kB 00:00
(2/8): base/7/x86_64/group_gz | 165 kB 00:00
(3/8): nodesource/x86_64/primary_db | 48 kB 00:00
(4/8): remi-safe/primary_db | 1.6 MB 00:00
(5/8): epel/x86_64/updateinfo | 1.0 MB 00:01
(6/8): base/7/x86_64/primary_db | 6.0 MB 00:01
(7/8): updates/7/x86_64/primary_db | 1.9 MB 00:01
(8/8): epel/x86_64/primary_db | 6.8 MB 00:02
依存性の解決をしています
–> トランザクションの確認を実行しています。
—> パッケージ nodejs.x86_64 2:8.16.2-1nodesource を インストール
–> 依存性解決を終了しました。

依存性を解決しました

================================================================================
Package アーキテクチャー
バージョン リポジトリー 容量
================================================================================
インストール中:
nodejs x86_64 2:8.16.2-1nodesource nodesource 16 M

トランザクションの要約
================================================================================
インストール 1 パッケージ

総ダウンロード容量: 16 M
インストール容量: 49 M
Is this ok [y/d/N]: y
Downloading packages:
警告: /var/cache/yum/x86_64/7/nodesource/packages/nodejs-8.16.2-1nodesource.x86_64.rpm: ヘッダー V4 RSA/SHA512 Signature、鍵 ID 34fa74dd: NOKEY
nodejs-8.16.2-1nodesource.x86_64.rpm の公開鍵がインストールされていません
nodejs-8.16.2-1nodesource.x86_64.rpm | 16 MB 00:02
file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL から鍵を取得中です。
Importing GPG key 0x34FA74DD:
Userid : “NodeSource
Fingerprint: 2e55 207a 95d9 944b 0cc9 3261 5ddb e8d4 34fa 74dd
Package : nodesource-release-el7-1.noarch (installed)
From : /etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
上記の処理を行います。よろしいでしょうか? [y/N]y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告: RPMDB は yum 以外で変更されました。
インストール中 : 2:nodejs-8.16.2-1nodesource.x86_64 1/1
検証中 : 2:nodejs-8.16.2-1nodesource.x86_64 1/1

インストール:
nodejs.x86_64 2:8.16.2-1nodesource

完了しました!

$ node -v
v8.16.2

node.jsのこと

PHPと同じところ
・サーバーサイド言語
違うところ
・非同期処理を行う
・単純な処理を同時に高速に行える

テストアプリ(my-app)を作ってみます

$ npx create-react-app my-app
npx: 91個のパッケージを7.62秒でインストールしました。

Creating a new React app in /[directory]/my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts…

> core-js@2.6.10 postinstall /[directory]/my-app/node_modules/babel-runtime/node_modules/core-js
> node postinstall || echo “ignore”

> core-js@3.2.1 postinstall /[directory]/my-app/node_modules/core-js
> node scripts/postinstall || echo “ignore”

+ react@16.10.2
+ react-dom@16.10.2
+ react-scripts@3.2.0
added 1496 packages from 687 contributors and audited 904959 packages in 72.04s
found 0 vulnerabilities

Success! Created my-app at /[directory]/my-app
Inside that directory, you can run several commands:

npm start
Starts the development server.

npm run build
Bundles the app into static files for production.

npm test
Starts the test runner.

npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

cd my-app
npm start

Happy hacking!

コメント

タイトルとURLをコピーしました