I am using a Windows 7 computer and do not have administrator access. Therefore I can not place a dot emacs file in the root directory. Is there a way for me to specify a different location for the dot emacs file?
-
If you can control your own location of the Emacs installation (e.g., putting it wherever you want, or at least have write access to the installation), then you can take complete control by using something like `site-start.el` to load your own `init.el` and you no longer need a `.emacs`. In this example, you don't need to fiddle with the home directory (unless someone else on the computer is putting stuff in there that will affect what you do). In other words, it can be blank and you never need to touch it. – lawlist Jun 03 '15 at 19:14
6 Answers
On every Windows install on which I use Emacs, I have the following code in a .emacs
file at the listed location:
;; Place this file in C:\Users\Username\AppData\Roaming and point to the appropriate files
(setq user-init-file "C:/path/to/.emacs")
(setq user-emacs-directory "C:/path/to/.emacs.d/")
(setq default-directory "C:/whatever/you/want/to/start/in")
(setenv "HOME" "D:/my/home/directory")
(load user-init-file)
This way I can put my .emacs
and .emacs.d/
anywhere I want.

- 3,989
- 1
- 26
- 49
-
Thank you, almost just what I needed. I left off the default-directory and sentenv HOME but otherwise it's what I needed to setq! – Grant Bowman Dec 10 '17 at 04:01
-
I tried Ryan's answer. But, now I am not able to open this file within emacs from AppData\Roaming folder. Kindly excuse me, as I couldn't add comment because, I don't have 50 points yet. – Sreekumar R Dec 16 '17 at 09:53
-
@SreekumarR Your should ask a new question, linking to this one, instead of posting an "Answer" – Andrew Swann Dec 16 '17 at 11:14
-
@SreekumarR If you have a new question, please ask it by clicking the [Ask Question](https://emacs.stackexchange.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/low-quality-posts/10342) – Stefan Dec 16 '17 at 13:18
Emacs has several places it looks for init files, as documented in the manual. If you want to customize Emacs you must start with one of those files.
A common approach is to use the file init.el
in your user-emacs-directory
, instead of having a .emacs
in your HOME directory.
The user-emacs-directory
defaults to ~/.emacs.d
, so it is still relative to your HOME, but the benefit of this approach is you can keep everything related to your Emacs configuration in one place. That directory could be under version control, backed up, shared across multiple machines, etc. You can use a symlink (mklink
on Windows) to keep the files in some other location.
For example, it is quite common to see folks maintain their Emacs configuration on Github. You can find lots of examples of this by searching Github for elisp projects with init.el files.

- 20,175
- 1
- 51
- 83
-
1I like this solution and would like to use it however it still does not tell me how to change my `user-emacs-directory` – Startec Jun 04 '15 at 00:11
-
My suggestion was to use symlinks, really. As shown by the other answers you need to put *something* in one of the standard locations Emacs reads during init, even if all it does is load your config from somewhere else. – glucas Jun 04 '15 at 00:22
-
Your .emacs file goes in your HOME
directory. From the Emacs manual:
The Windows equivalent of HOME is the user-specific application data directory. The actual location depends on the Windows version...
You can override this default value of HOME by explicitly setting the environment variable HOME to point to any directory on your system. HOME can be set either from the command shell prompt or from ‘Properties’ dialog of ‘My Computer’. HOME can also be set in the system registry, see MS-Windows Registry.

- 21,719
- 1
- 52
- 92
-
2Yes, I know how to set the home directory however for version control reasons I want to be able to set emacs to read from a different directory (so that I can have a directory specific to emacs) – Startec Jun 03 '15 at 18:21
-
3Note that this hack makes Emacs consider something else as the home directory. – wasamasa Jun 03 '15 at 18:34
-
@wasamasa - I wouldn't call it a "hack". On my build of Emacs 25, if you don't set "HOME" with an environment variable, it defaults to the Emacs install directory, which is quite clearly wrong. "HOME" should be set to what the user considers their home directory, and setting the environment variable is the intended standard way to do that. On Unix systems this is usually already done for the user during the login process, but on Windows you have to manually do it. – T.E.D. Sep 19 '19 at 20:40
-
The point of this is to change what you'd normally consider your `HOME` directory to something wildly different. Hence why I call that change a hack. Setting it to its appropriate value is obviously fine. – wasamasa Sep 20 '19 at 06:11
You say:
I know how to set the home directory however for version control reasons I want to be able to set emacs to read from a different directory (so that I can have a directory specific to emacs).
Your init file goes in your home directory, which you can put anywhere. Apparently you want to have a different directory for stuff that Emacs loads. That's not a problem. Put your init file in your home directory, and have that file add another directory to the value of variable load-path
and then require whatever other Emacs libraries you want to use. Put those libraries in that other directory.
IOW, your init file need not contain anything beyond setup of the directory where you keep the Emacs libraries that you want to load.

- 75,699
- 9
- 109
- 225
Just for the sake of completeness, I provide a link to:
https://www.gnu.org/software/emacs/manual/html_node/efaq-w32/Location-of-init-file.html
Which says that you can set a HOME
value in the registry path:
HKCU\SOFTWARE\GNU\Emacs\HOME
But this value is overridden by the environment variable HOME
.

- 285
- 2
- 9
Think you could put (setq user-init-file "C:/path/to/.emacs")
and other lines proposed by @ryan into site-start.el
Your site may also have a site startup file; this is named site-start.el, if it exists. Like default.el, Emacs finds this file via the standard search path for Lisp libraries. Emacs loads this library before it loads your init file.

- 143
- 5