I'm new to emacs and looking to change my default init file as the current is set to be ~/.emacs and I want it to be ~/.emacs.d/init.el

I can clearly C-h v user-init-file to see but but M-x set-variable user-init-file just gives [No Match].

  • 1
    Where are you going to change the value of user-init-file? In the init file? That's too late. You should think of it as a read-only variable that's compiled into emacs. To change it, you'd have to recompile emacs. But current versions look for either file, so you can just rename your .emacs to ~/.emacs.d/init.el and you should be OK.
    – NickD
    Commented Sep 17, 2017 at 18:19
  • My problem is that I'm a noob, just trying to load his first few lines of lisp into the init file, however no init file loads on startup. From googling around I've found it's because my user-init-file is set to be ~/.emacs whereas the default folder created was ~/.emacs.d/
    – jamezyx
    Commented Sep 17, 2017 at 18:25
  • How do you know that no init file loads on startup? Googling around is dangerous: your problem may have nothing to do with what you found. Try deleting any existing .emacs file, put (message "Hello world") in ~/emacs.d/init.el and start up emacs. Do you see the message in the minibuffer?
    – NickD
    Commented Sep 17, 2017 at 18:34
  • I tried putting the hello world in and still nothing. A C-h e shows no init file loaded: Loading 00debian-vars...done Loading /etc/emacs/site-start.d/50autoconf.el (source)...done Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)... Loading debian-ispell... Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...done Loading debian-ispell...done Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...done Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
    – jamezyx
    Commented Sep 17, 2017 at 18:38
  • Even emacs -q -l ~/.emacs.d/init.el give the error "no such file or directory" but it 100% does exist
    – jamezyx
    Commented Sep 17, 2017 at 18:41

1 Answer 1


Why "No match"

The function set-variable will only accept setting user options. But user-init-file is not a user option (i.e. it was not designed to be customized). Relevant excerpt from the docstring of set-variable :

VARIABLE should be a user option variable name

Why user-init-file is not a user option

This variable is meant to be read, not modified. The reason is that at the moment you can write code to modify this variable (i.e. while emacs is starting, or after it has started), it is already too late : the init file is already loaded (or is being loaded).

How to change the init file

There are various ways to tell emacs what to load at startup. Details can be found at (info "(emacs) Init File"). I think the easiest is : prevent emacs from loading any init file then load another one instead (i.e. use -q -l somefile.el when invoking emacs).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.