# What is the right place for user-defined init.m?

What is the right folder to put a file init.m which will be run after all other init.m files applied by the various components of Mathematica have done their job?

I would like to use it to do something like

AppendTo[$Path, *my favourite place*]; Unprotect[Needs]; Needs[x_] := Needs[x, ContextToFileName[x]]; Protect[Needs]; Needs["CleanSlate`"]; SetOptions[FileNames, IgnoreCase->True]; ClearAttributes[If, HoldAll]; SetAttributes[If, HoldRest]; ClearAttributes[Switch,HoldAll]; SetAttributes[Switch, HoldRest]; Unprotect[RGBColor]; RGBColor[{x_, y_, z_}] := RGBColor[x, y, z]; Protect[RGBColor]; Unprotect[MantissaExponent]; MantissaExponent[i_?IntegerQ] := MantissaExponent[1.*i] Protect[MantissaExponent]; ... and other things which make my work go smoother. Previously (in Version 4.0) C:\Program Files\Wolfram Research\Mathematica\4.0\AddOns\Autoload\init.m or C:\Program Files\Wolfram Research\Mathematica\4.0\SystemFiles\FrontEnd\init.m were the right places for this type of operations. • FileNameJoin[{$UserBaseDirectory,"Kernel","init.m"}] Oct 21 '14 at 15:25
• – Öskå
Oct 21 '14 at 15:46

There are two typical locations where a user can add an init.m file to be loaded at run-time: $BaseDirectory and$UserBaseDirectory. $BaseDirectory is useful for installation wide customizations that apply to all users while$UserBaseDirectory is used for a specific users customizations. So, anything in $UserBaseDirectory is loaded after the files found in$BaseDirectory so that the user's preferences are heeded. For most users, this distinction is likely not to matter as they are the only user of their computer. However, I would recommend using $UserBaseDirectory as it is less messy, and it provides you with several opportunities for customization. From this tutorial on the system file layout, there are two locations where a global init.m will be picked up on load: • FileNameJoin[{$UserBaseDirectory,"Kernel"}]
• FileNameJoin[{$UserBaseDirectory,"FrontEnd"}] where an init.m file will be loaded when the respective component is loaded (kernel or front-end). The subdirectories in$UserBaseDirectory is also where your custom style-sheets would go, but that is off topic for the question.
• Files in $UserBaseDirectory will (should) also remain when you uninstall Mathematica or upgrade versions. They are also simpler to back-up. Oct 21 '14 at 18:28 • But FileNameJoin[{$UserBaseDirectory,"FrontEnd"}] is the one, which is rewritten on every start of Mathematica. This is certainly not the right place to store any customization! Oct 22 '14 at 16:27
• @AdalbertHanßen yes and no. My take on it is that the FE reads in init.m, and then spits out a modified version based upon what has changed during the session. In fact, if it finds stuff in it doesn’t recognize, it will assume it is corrupt and replace it with the default version which can be a bit disconcerting upon opening. However, the settings within the SetOptions[$FrontEnd,...] can be modified, and they are respected. So, it looks like you’re limited to the FrontEnd Options. Oct 22 '14 at 16:54 The place given by$UserBaseDirectory or by \$UserDirectory did not work for me in Version 10.4.0 for Microsoft Windows (64-bit) (February 26, 2016).