Help us understand the problem. What is going on with this article?

パスを通すとは Linux 

メモ

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

全体像

  • 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

とおた

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした