# Variable user-init-file not found (No Match) when trying to set it, but it's documented and has a value when examined

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].

• 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 Sep 17 '17 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 Sep 17 '17 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 Sep 17 '17 at 18:34
• Even emacs -q -l ~/.emacs.d/init.el give the error "no such file or directory" but it 100% does exist – jamezyx Sep 17 '17 at 18:41

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).