简体   繁体   中英

How to run 'rails credentials:edit' on Windows 10 without installing a Linux Subsystem

I am trying to run the following command on my Rails app on my Windows 10 machine:

rails credentials:edit

But I get the following error message:

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.

I did some research, and I understand that most people who want to run such aforementioned command on Windows 10 will need to install a Linux Subsystem on their Windows machines. However, such option is not available for me because I don't have admin rights on my machine. I have attempted installing a Linux subsystem by using resources like the one here without luck.

I didn't find any of the answers above worked for me. Notepad complained about the directory being incorrect and gave me a blank file.

I got it to work with Notepad++ by doing the following:

SET EDITOR="C:\Program Files\Notepad++\notepad++.exe"
rails credentials:edit

I didn't need to use the --wait flag.

I'm using VS Code and Powershell within VS Code, and this works for me:

> $env:EDITOR="code --wait"
> rails credentials:edit

Credit goes to this article https://flexpoint.tech/2020/05/16/editing-rails-6-0-credentials-on-windows/ by J. Pablo Fernández

I would suggest you switch to non-windows based system if you're trying to do any rails development as I used to work on a windows machine until I caved in and switched entirely to Mate Linux. It would be so much easier to develop Rails application on Linux platform since you would see almost all gems compiling without any issue and all the rails terminal commands are working without further setup.

However, if you would like to edit your credentials, you need a text editor (Usually vim on Linux) setup before running credentials:edit.

First run SET EDITOR="notepad_path" and then try running rails credentials:edit

You can change notepad_path to any other text editor you prefer. However, some editors like Atom was giving weird issues for me.

  1. find your pathing to your local text editor (for windows its Notepad) you can search notepad and right-click and open the file location
  2. right-click notepad and open properties then copy the Target:(EX.( "%windir%\\system32\\notepad.exe"))
  3. now paste the target in SET EDITOR="target_path" EX. SET EDITOR="%windir%\\system32\\notepad.exe"
  4. now you can run bundle exec rails credentials:edit and notepad should come up with the decrypted info

If you are in a Windows environment, I highly recommend to use the classic notepad. In my experience using Notepad++, sometimes it opened correctly but didn't save, instead it works perfect with the classic notepad.

Also to run those mentioned commands, better use the classic cmd shell console, it might not work properly in PS (Power Shell) console. Good luck!

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.

solution:

$env:EDITOR="notepad"
rails credentials:edit

I'm using windows 10 and here are the steps that I took:

  1. make sure you have the path of your text editor in 文本编辑器的
    • to do that, copy the file location of your text editor
    • right click on my computer(This PC) > select properties > advanced system settings > environment variables
    • on System variable box, click for "Path" > click edit > new > paste text editor file location
  2. restart command line then try to open text editor using the command line. I'm using sublime and entering "subl" will open sublime text editor
  3. cd to your project folder then run the following command:
set EDITOR=subl --wait
  • where subl is the executable file of the text editor
  • also without double or single quote, this will work since subl is an executable file and was registered on environment variable (if using notepad use: notepad).
  • Without the --wait flag, your will be saved immediately without giving you the chance to edit.将立即保存,而您没有机会进行编辑。
  • alternatively you can directly set EDITOR similar to this:
set EDITOR="C:\filepath\to\your\editor --wait"
  • this time with quotes

    1. Finally run:
rails credentials:edit

[Windows 8.1]

I'm using SET EDITOR="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin command to set the editor and it works.

Next, just run rails credentials:edit command. Then you can edit the credentials.yml file. Save it and close the Notepad++ windows. Then the credentials is encrypted and saved automatically.

Got it working (using PowerShell) with

$env:EDITOR="notepad"

then

bundle exec rails credentials:edit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM