Issue to open credentials file

Viewed 10470

I am trying to open credentials file with this command.

rails credentials:edit

It returns :

No $EDITOR to open file in. Assign one like this:

EDITOR="mate --wait" bin/rails credentials:edit

For editors that fork and exit immediately, it's important to pass a wait flag, otherwise the credentials will be saved immediately with no chance to edit.

So I make this command :

EDITOR="subl --w" bin/rails credentials:edit

However, terminal responds with "New credentials encrypted and saved" without opening an editor.

7 Answers

Are you using the correct alias for wait? In official documentation there is:
-w or --wait: Wait for the files to be closed before returning

So it should be:
EDITOR="subl --wait" bin/rails credentials:edit.

I've just tested this on ubuntu with vs code, and atom and it worked correctly:
EDITOR="code --wait" rails credentials:edit.
EDITOR="atom --wait" rails credentials:edit.

Also check if subl is correctly added to system variable path.

EDITOR="vim" rails credentials:edit

example using any environment:

EDITOR="vim" rails credentials:edit --environment=production

As a VS Code user, this took me a while to figure out. What was missing to install the code command through VS Code's interface.

Crossposting Bryan's answer here:

  • Launch VS Code.
  • Open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install code command in PATH command.
  • Now run EDITOR="code --w" bin/rails credentials:edit

There might be a similar missing step for Sublime users.

If you want to run vim inside of a devcontainer:

sudo apt update
sudo apt install vim

EDITOR="vim --nofork" bin/rails credentials:edit

As nuaky answered, the following command helps me (assume terminal command line in app folder):

$ EDITOR="subl --wait" rails credentials:edit

I know this is an old question but I spent a good hour trying to get this answer. The following worked for me

MAC - Catalina 10.15.4
Rails Version= 6.0.3.2
Ruby Version= 2.7.0

I run on the terminal

EDITOR="subl -w" bin/rails credentials:edit

And it allowed me to edit the credentials.yml.enc file.

For all the Windows 10/11 users: setup the editor using the following command:

$env:EDITOR="notepad"

Now run this command to edit the credentials file:

bundle exec rails credentials:edit --environment development
Related