Macが突然壊れたので新しいMacを購入した。
現在、Webサイトを運営中でそれの更新作業を新しいMacでしようとした時に、ローカル環境で検証できないようになっていた。
具体的には、ターミナルでhttp-serverコマンドを打ってもエラーが出てくる。
新しいMacを購入してから環境構築をして無いねんから、そりゃ当然ですね。
とうことで、環境構築をすることにしましたが、ちょこちょこ詰まったので、ここに残しておきます。
主にこちらの記事を参考にさせていただきました。
https://qiita.com/standard-software/items/1afe7b64c4c644fdd9e4
とりあえずhttp-server コマンドのインストール
とにもかくにも、まずインストールを試みる
% npm install http-server -g
しかし、下記応答が。。。
zsh: command not found: npm
command not found: npmと出た時の対処
npmコマンドが使えないよ。とのことなので、以下の記事を参考にして進める。
https://qiita.com/sinmetal/items/154e81823f386279b33c
基本的には上記のリンク先通りにすればオッケー
ここでは、その過程で詰まったところを記載します。
source ~/.bash_profileコマンドで大量のエラー
.bash_profile が見当たらなかったので、下のサイトを見ながら、ホームに.bash_profile を作成。
http://banker0507.blogspot.com/2012/11/macbashprofile.html
https://qiita.com/sinmetal/items/154e81823f386279b33c
上記リンクに沿って下記コマンドを実行
% source ~/.bash_profile
すると下記のエラーが
command not found: rtf1ansiansicpg932cocoartf2513
command not found: cocoatextscaling0cocoaplatform0{fonttblf0fmodernfcharset0
command not found: colortbl
command not found: red255green255blue255
command not found: red255green255blue255
command not found: red83green83blue83
parse error near `;;'
なんだこれは?とりあえず.bash_profileの中身を見てみる
% cat .bash_profile
{\rtf1\ansi\ansicpg932\cocoartf2513
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;\red255\green255\blue255;\red83\green83\blue83;}
{\*\expandedcolortbl;;\cssrgb\c100000\c100000\c100000;\cssrgb\c40000\c40000\c40000;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\sl380\partightenfactor0
\f0\fs26 \cf2 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec2 export PATH="/usr/local/bin:$PATH:/usr/local/sbin"\
export PATH=$HOME/.nodebrew/current/bin:$PATH
}
なぜかよくわからない文がたくさん、、、
viで中身を編集し、下記の状態にする。
% cat .bash_profile
export PATH="/usr/local/bin:$PATH:/usr/local/sbin"
export PATH=$HOME/.nodebrew/current/bin:$PATH
もう一度
% source ~/.bash_profile
無事エラーなしで解決
http-server実行でローカル環境での検証環境構築成功
その後もせこせこと参考ページを見ながらインストール等を実施し、最後に
% http-server
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://192.168.10.7:8080
Hit CTRL-C to stop the server
http://localhost:8080/
にアクセスすると、、、、
無事、ローカルでの検証環境を構築することができました!
上記のサーバを停止したいときはcontrolキーとCを同時に押してください。