35

I've installed successfully chef on my workstation but when i am trying to create a role using the following command

knife role create startmeup

I get

ERROR: RuntimeError: Please set EDITOR environment variable

Any idea what the problem is?

Machavity
  • 30,841
  • 27
  • 92
  • 100
GigaPr
  • 5,206
  • 15
  • 60
  • 77

11 Answers11

45

You have to define EDITOR as environment variable.

Try

export EDITOR=$(which vi)

To persist this, add it to ~/.bashrc or ~/.bash_profile.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
  • How do I set the Editor in Windows? – GigaPr Mar 25 '13 at 13:58
  • You can do it the same way - at least as long as your using `msysgit`. Open the Git Bash and execute a `ls .bash*` to see, if one of the files `.bashrc` or `.bash_profile` exist. Then edit (or create a new one) and place that line there. – StephenKing Mar 26 '13 at 07:15
  • 1
    If you're not using the Git Bash, please provide more info. – StephenKing Mar 26 '13 at 07:17
  • 4
    On Windows, I had to specify the full path, using escaped 8.3 notation, e.g. knife[:editor] = "C:\\Progra~2\\Notepa~1\\Notepad++.exe". See https://tickets.opscode.com/browse/CHEF-4503 – Alan Feb 19 '14 at 22:08
  • 1
    You can also configure it in single quotes and double quotes. That is: `knife[:editor] = '"C:\Program Files (x86)\Notepad++\notepad++.exe"'` works. – Epu Aug 22 '14 at 17:48
  • I had some trouble getting the right syntax in Ubuntu. `export EDITOR="/usr/bin/nano"` worked for me. – Eric Engel Jan 21 '15 at 02:47
28

In your knife.rb file (~/.chef/knife.rb) add the following line for notepad++ :

knife[:editor] = "C:\\progra~2\\notepa~1\\notepad++.exe -nosession -multiInst"

or if you just want to use notepad

knife[:editor] = "notepad"

or emacs for GNU

knife[:editor] = "emacs"
vesuvious
  • 2,753
  • 4
  • 26
  • 39
5

I use something like this:

knife role create startmeup -e vi
Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
Vitaliy
  • 51
  • 1
  • 1
3

If you want to set it for that session, the command

set EDITOR="C:\Program Files (x86)\Notepad++\notepad++.exe"

works.

Community
  • 1
  • 1
3

There're a few ways to deal with the problem.

  1. set the environment variable $EDITOR. You can export it by export EDITOR=vim in shell, or put this line in files like .bashrc;

  2. pass the option -e vim (namely --editor vim)to the knife command. For example, you can do it like this:

    knife role create startmeup -e vim

  3. modify ~/.chef/knife.rb by add this line:

    knife[:editor] = "vim"

Community
  • 1
  • 1
Yun Zhao
  • 183
  • 12
2

Just set your editor and it will work. In my case I use vim editor that's why my command was as follows:

export EDITOR=vim
Tanmay
  • 746
  • 6
  • 7
0
export EDITOR=vi   

In my case it worked.but for ubuntu14.o version vi editor backspace is not working.

xlecoustillier
  • 16,183
  • 14
  • 60
  • 85
0

Adding this entry to the knife config file worked for me

knife[:editor] = "Notepad"
GigaPr
  • 5,206
  • 15
  • 60
  • 77
0

If you have notepad++ installed in your machine :

knife environment create startmeup -e notepad++
0

Knife prioritizes knife.rb over the environment variable.

It seems knife will default to vim (on my system, anyway) if no config is provided, so it is safe to omit the value until you're ready to configure your environment for a custom editor (in my case, a script).

Rew Brian
  • 23
  • 5
-2

There is no explicit way to set the variable under knife.rb. Its good to export on your shell using $export EDITOR=vim (or any of those that you would like to keep).

Even without setting variable under knife.rf it works. Just export the EDITOR by setting the appropriate value.