LoginSignup
0
0

More than 3 years have passed since last update.

direnvを使ってプロダクト毎に公開したくない環境変数を設定する

Posted at

direnvとは

direnv is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory.

シェルの拡張機能ということで、.envrcというファイルを生成し、そこに環境変数を記述すると、このファイルがあるディレクトリ上でのみ記述した環境変数が有効になるという代物です。

インストール

homebrewで簡単にインストールできます。

$ brew install direnv

zshにパスを通します。

## direnv
export EDITOR="vi"
eval "$(direnv hook zsh)"

読ませます。

source ~/.zshrc

環境変数を設定したいプロダクトのディレクトリに移動して以下のコマンドを打つとviが起動するので、設定したい環境変数を設定します。

$ direnv editor .
export GOOGLE_CLIENT_ID=******************
export GOOGLE_CLIENT_SECRET=*****************

このようにしてみてから、ディレクトリ内と外でechoを使って環境変数が適応されているのとされていないのを確認してみてください。

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