0
1

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.

パスを通すとは Linux 

Posted at

メモ

パスを通す事の理解が難しい理由として、若干コンピューターの深いところに触れるので、情報処理などを学んでいないと取っ付きにくい

全体像

  • install
  • パスを通す
  • コマンドの実行

パスの通し方

  • 現在のpathの確認
echo $PATH 

# 縦に並べたい場合はこれ
echo $PATH | tr ':' '\n'
  • 実行したいコマンドのパスの確認
whichコマンド

  bin which postgres
/usr/local/opt/postgresql@9.6/bin/postgres
  • パスを通す
exportコマンド

export PATH="$PATH:/opt/local/bin"

環境変数$PATHの最後に「:/opt/local/bin」という記述する

「/opt/local/bin」というパスを追加したことになる

この記事参考
https://qiita.com/Naggi-Goishi/items/2c49ea50602ea80bf015

検証

  • postgres
postgresのコマンドを確認して見る
➜  bin which postgres
/usr/local/opt/postgresql@9.6/bin/postgres
実行したいコマンド【pg_ctl】

pg_ctl -D /usr/local/var/postgresql@9.6 start
➜  bin pwd
/usr/local/opt/postgresql@9.6/bin
pg_ctlがはいっている
➜  bin ls
clusterdb         pg_controldata    pg_upgrade
createdb          pg_ctl            pg_xlogdump
createlang        pg_dump           pgbench
createuser        pg_dumpall        pltcl_delmod
dropdb            pg_isready        pltcl_listmod
droplang          pg_receivexlog    pltcl_loadmod
dropuser          pg_recvlogical    postgres
ecpg              pg_resetxlog      postmaster
initdb            pg_restore        psql
oid2name          pg_rewind         reindexdb
pg_archivecleanup pg_standby        vacuumdb
pg_basebackup     pg_test_fsync     vacuumlo
pg_config         pg_test_timing
binまでパスがとおっている
➜  bin  echo $PATH | tr ':' '\n'
/usr/local/opt/openssl/bin
/usr/local/opt/postgresql@9.6/bin

実践

現在elasticsearchのパスが通っていない。
バージョンが混在しているので、、、、

パスを確認してみる
echo $PATH | tr ':' '\n'


# 結果

 /usr/local/Cellar/elasticsearch/2.3.1/bin

# 実際は
/usr/local/Cellar/elasticsearch/6.2.4/bin
現状
➜  ~ elasticsearch
zsh: permission denied: elasticsearch

これなんか想定してたのと違うけど。。permission?笑
パスを通す

export PATH="$PATH:/opt/local/bin"

export PATH="$PATH:/usr/local/Cellar/elasticsearch/6.2.4/bin"


結果
➜  ~ elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file logs/gc.log due to No such file or directory

[2019-10-22T12:38:58,984][INFO ][o.e.n.Node               ] [] initializing ...
[2019-10-22T12:38:59,059][INFO ][o.e.e.NodeEnvironment    ] [Ans3M-O] using [1] data paths, mounts [[/ (/dev/disk1s1)]], net usable_space [70.6gb], net total_space [233.4gb], types [apfs]
[2019-10-22T12:38:59,060][INFO ][o.e.e.NodeEnvironment    ] [Ans3M-O] heap size [989.8mb], compressed ordinary object pointers [true]
[2019-10-22T12:38:59,061][INFO ][o.e.n.Node               ] node name [Ans3M-O] derived from node ID [Ans3M-OBRb2WHf0belsS5A]; set [node.name] to override
[2

とおた

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?