LoginSignup
484

More than 1 year has passed since last update.

.bash_profileと.bashrcのまとめ

Last updated at Posted at 2017-12-25

はじめに

bashを使うにあたり、使用環境をユーザ好みにカスタマイズができる。

  • .bash_profile
  • .bashrc

この2つが設定ファイルである。
それぞれのファイル設定の使い分けをまとめる。

.bash_profile

ログイン時に1回、実行される。
例えば、ターミナル.appを起動した際に読み込まれる。

このファイルには具体的に何を設定すれば良いのかは、

  • 環境変数(exportで宣言する変数)

を設定すると良い。

.bashrc

シェル起動時に1回、実行される。
コマンドライン上でbashと叩くと再度.bashrcが読み込まれる。(.bash_profileは読まれない)
シェルを起動する度に毎回設定したい場合はこのファイルに設定を入れる。

このファイルには具体的に何を設定すれば良いのかは、

  • エイリアス
  • シェル関数
  • コマンドラインの補完

を設定すると良い。

#設定ファイルをつくる

上記2つのファイルはどこに配置しているのか。

~/.bash_profile
~/.bashrc

ともにホームディレクトリにある。
しかし人によってはファイルがない場合もあるよう。(私は2つともなかった)

、、、なので作ります。
touchコマンドで空のファイルを作成する

$ touch ~/.bash_profile
$ touch ~/.bashrc

ファイルができたことを確認

$ ls -a

.bash_profile		.viminfo		Public
.bash_sessions		Applications		VirtualBox VMs
.bashrc

これで設定ファイルができた。
どのような設定を行うかはまだ別のエントリに。。。

#参考
本当に正しい .bashrc と .bash_profile の使ひ分け
.bash_profile と .bashrc は何が違うの?使い分けを覚える

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
484