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].
Why "No match"
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
VARIABLE should be a user option variable name
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).