[RUBY] [Beginner] Environment variable setting -dotenv-rails-

What are environment variables?

Environment variables are like boxes that hold information that can't be uploaded to Github. As a result, you do not have to write the password directly in the application. By passing data from the OS, you can run the application without worrying about information leakage.

Setting method

gem installation

Gemfile


gem 'dotenv-rails'
$ bundle install
Create .env file

In the root directory where the Gemfile is located Create an .env file

Creating environment variables
KEY='*******' #Enter the key and password you want to use
SECRET_KEY='*******'

When calling

ENV['KEY']

You can call it.

Excluded from Git control

.gitignore


/.env

If you forget this, information will be leaked, so be sure to set it.

Recommended Posts

[Beginner] Environment variable setting -dotenv-rails-
A memorandum of the environment variable "JAVA_HOME" path setting procedure
[Eclipse Java] Development environment setting memo
Java environment variable settings (Windows, AdoptOpenJDK11)
Setting project environment variables in intelliJ