简体   繁体   English

如何在不安装 Linux 子系统的情况下在 Windows 10 上运行“rails credentials:edit”

[英]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:我正在尝试在我的 Windows 10 机器上的 Rails 应用程序上运行以下命令:

rails credentials:edit

But I get the following error message:但我收到以下错误消息:

No $EDITOR to open file in. Assign one like this:没有 $EDITOR 来打开文件。像这样分配一个:

EDITOR="mate --wait" bin/rails credentials:edit EDITOR="mate --wait" bin/rails 凭证:编辑

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.对于立即 fork 和退出的编辑器,传递一个等待标志很重要,否则凭据将立即保存而没有机会进行编辑。

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.我做了一些研究,我知道大多数想要在 Windows 10 上运行上述命令的人需要在他们的 Windows 机器上安装 Linux 子系统。 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.我曾尝试使用像这里这样的资源来安装 Linux 子系统,但没有运气。

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:我通过执行以下操作使其与 Notepad++ 一起使用:

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

I didn't need to use the --wait flag.我不需要使用--wait标志。

I'm using VS Code and Powershell within VS Code, and this works for me:我在 VS Code 中使用 VS Code 和 Powershell,这对我有用:

> $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归功于 J. Pablo Fernández 撰写的这篇文章https://flexpoint.tech/2020/05/16/editing-rails-6-0-credentials-on-windows/

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.如果您尝试进行任何 Rails 开发,我建议您切换到基于非 Windows 的系统,因为我曾经在 Windows 机器上工作,直到我屈服并完全切换到 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.在 Linux 平台上开发 Rails 应用程序会容易得多,因为您会看到几乎所有 gems 编译都没有任何问题,并且所有 rails 终端命令都可以在没有进一步设置的情况下工作。

However, if you would like to edit your credentials, you need a text editor (Usually vim on Linux) setup before running credentials:edit.但是,如果您想编辑您的凭据,则需要在运行凭据之前设置文本编辑器(通常在 Linux 上为 vim):edit。

First run SET EDITOR="notepad_path" and then try running rails credentials:edit首先运行SET EDITOR="notepad_path"然后尝试运行rails credentials:edit

You can change notepad_path to any other text editor you prefer.您可以将 notepad_path 更改为您喜欢的任何其他文本编辑器。 However, some editors like Atom was giving weird issues for me.然而,像 Atom 这样的一些编辑给我带来了奇怪的问题。

  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找到本地文本编辑器的路径(对于 Windows,它的记事本)您可以搜索记事本并右键单击并打开文件位置
  2. right-click notepad and open properties then copy the Target:(EX.( "%windir%\\system32\\notepad.exe"))右键单击记事本并打开属性,然后复制目标:(EX.( "%windir%\\system32\\notepad.exe"))
  3. now paste the target in SET EDITOR="target_path" EX.现在将目标粘贴到 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现在你可以运行bundle exec rails credentials:edit和记事本应该提供解密的信息

If you are in a Windows environment, I highly recommend to use the classic notepad.如果您在 Windows 环境中,我强烈建议您使用经典记事本。 In my experience using Notepad++, sometimes it opened correctly but didn't save, instead it works perfect with the classic notepad.根据我使用 Notepad++ 的经验,有时它可以正确打开但没有保存,而是与经典记事本完美配合。

Also to run those mentioned commands, better use the classic cmd shell console, it might not work properly in PS (Power Shell) console.同样要运行这些提到的命令,最好使用经典的 cmd shell 控制台,它可能无法在 PS(Power Shell)控制台中正常工作。 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:我正在使用 Windows 10,以下是我采取的步骤:

  1. make sure you have the path of your text editor in environment variables PATH确保您在环境变量 PATH 中有文本编辑器的路径
    • 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我正在使用 sublime 并输入“subl”将打开 sublime 文本编辑器
  3. cd to your project folder then run the following command: cd 到您的项目文件夹,然后运行以下命令:
set EDITOR=subl --wait
  • where subl is the executable file of the text editor其中 subl 是文本编辑器的可执行文件
  • 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).也没有双引号或单引号,这将起作用,因为 subl 是一个可执行文件并已在环境变量中注册(如果使用记事本,请使用:记事本)。
  • Without the --wait flag, your credentials.yml.enc will be saved immediately without giving you the chance to edit.如果没有 --wait 标志,您的credentials.yml.enc将立即保存,而您没有机会进行编辑。
  • alternatively you can directly set EDITOR similar to this:或者,您可以直接设置 EDITOR 类似于:
set EDITOR="C:\filepath\to\your\editor --wait"
  • this time with quotes这次有引号

    1. Finally run:最后运行:
rails credentials:edit

[Windows 8.1] [视窗 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.我正在使用SET EDITOR="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin命令来设置编辑器并且它可以工作。

Next, just run rails credentials:edit command.接下来,只需运行rails credentials:edit命令。 Then you can edit the credentials.yml file.然后您可以编辑credentials.yml文件。 Save it and close the Notepad++ windows.保存并关闭 Notepad++ 窗口。 Then the credentials is encrypted and saved automatically.然后凭据被加密并自动保存。

Got it working (using PowerShell) with让它工作(使用 PowerShell)

$env:EDITOR="notepad"

then然后

bundle exec rails credentials:edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows 10上的Linux子系统上安装Ngrok 2.0 - How to install Ngrok 2.0 on linux subsystem on Windows 10 在Windows 10上安装Rails时出错 - Error installing Rails on Windows 10 如何在Windows子系统Linux版上修复“ ECONNRESET:套接字挂起”? - How to fix 'ECONNRESET: socket hang up' on Windows Subsystem for Linux? 在 Linux 的 Windows 子系统上安装带有本机扩展的 Ruby gem 时,是否有可靠的方法来避免权限被拒绝错误? - Is there a reliable way to avoid permission denied errors when installing Ruby gems with native extensions on Windows Subsystem for Linux? 在 windows 10 上的导轨上安装 ruby 时出错 - Error installing ruby on rails on windows 10 在Ubuntu Bash Windows 10上安装rails - Installing rails on Ubuntu Bash Windows 10 使用Ruby on Rails安装heroku卡住了...(Windows 10) - Installing heroku with Ruby on Rails stucks… (Windows 10) Ruby on Rails如何创建在Windows 10中每5分钟运行一次的任务 - Ruby on rails how to create task that run on every 5 minute in windows 10 在Windows和Linux中使用不同的gemfile运行Rails App - Run Rails App In Windows and Linux with different gemfiles 如何在Vim内运行Rails而无需切换Windows - How to run rails inside vim without switching windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM