2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UbuntuにNode.js(npm,ejs and express)を入れる

Posted at

vagrantとvirtual boxを使って仮想環境を構築することが必要になったが、何度も失敗したので、書いておく。

まずUbuntuを入れる。
コマンドプロンプトで任意のファイルに

vagrant init ubuntu/trusty64
vagrant up

これでそのファイルにvagrantfileが作成される。

そのまま
https://nodejs.org/ja/download/package-manager/
に載っている方法でNode.jsをインストール

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

これでNode.jsのv.8系とnpmのある程度のバージョンがインストールされている。
バージョンの確認は

node -v //Node.jsのバージョン
npm -v //npmのバージョン

で確認が可能。

Node.jsのパッケージ(モジュール)のejsやexpressをインストールする。

npm install -g ejs
npm install -g express

でインストールは可能。
私の環境だと-gをつけるかどうかで、Node.jsが反応してくれなかったので、-gを付けた。
グローバル環境になるのがあんまりよくないとか言われたが、動かないと話にならないので、そこは自由に。

この状態でejsやexpressを動かそうとしても、エラーが出るときがある。

Cannot find module 'express'

みたいな感じで。
こうなったら

npm init
npm install --save express

みたいにしとくと、なんか知らんけど動くようになった。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?