How to Install Emacs Package Manually
This page is a tutorial on how to install emacs packages manually.
If you are using emacs 24 or later, it's better to use its ELPA package system instead. See: Emacs: How to Install Packages Using ELPA, MELPA.
There are hundreds of useful emacs packages on the web that are not bundled with emacs. Often, there is no install instruction included, and you may notice that each's installation methods seem to differ wildly. The following gives a overview on how emacs package are installed.
Loading the File
Load the File Manually
Suppose you downloaded a simple emacs package on the web named “xyz.el”. To use the package, all you have to do is to make emacs load the file.
- Alt+x
load-file
then give the file path. - Now, emacs is aware of the package. To activate, call the command in the package. For example, if the file name is
xyz.el
, then the command to activate it is typically “xyz” or “xyz-mode”.
Load File at Startup
If you want emacs to load the file when it starts, put the file in the dir ~/.emacs.d/lisp/
, (create that directory if it doesn't exist.) then put the following in your emacs init file:
;; Tell emacs where is your personal elisp lib dir (add-to-list 'load-path "~/.emacs.d/lisp/") ;; load the packaged named xyz. (load "xyz") ;; best not to include the ending “.el” or “.elc”
What is the Purpose of 〔~/.emacs.d/〕 Path?
By convention, the ~/.emacs.d/
is a dir for all your personal emacs files. It is the default value of the variable user-emacs-directory. On Windows, the path is %HOMEPATH%/.emacs.d/
.
[see Windows Environment Variables Basic Tutorial]
Emacs 23 should have created this dir for you. If it's not there, you can just create it yourself.
By convention, the dir ~/.emacs.d/lisp/
is for packages you manually installed.
Byte Compile
Elisp source code can be byte compiled. When a file is byte compiled, it loads faster, and the functions will run faster too (about 6 times faster). For simple packages, the difference in speed is not noticeable.
To compile your code, Alt+x byte-compile-file
. Once you compiled the code, you'll get a file with suffix “.elc”.
You can byte-compile multiple files. In dired
, press m to mark them (press u to unmark), then press B (diredp-byte-compile-this-file
).
[see File Management with Emacs (dired tutorial)]
(info "(elisp) Byte Compilation")
Auto-Activation of Mode When Opening File
This is usually setup by the package, but not always. Here's the basics:
;; setup files ending in “.js” to open in js2-mode (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
For detail, see: Emacs: Set File to Open in a Major Mode.
Mode Documentation
Emacs mode usually comes with doc string. To view it, first activate the mode (Alt+x mode_name). Once in the mode, Alt+x describe-mode
【Ctrl+h m】. Emacs will show its doc string.
Robust modes usually have graphical menus too. So, activate the mode, then you can check what menu commands it has in the menu bar.
Sometimes, a mode comes with complete documentation in info
format (file with suffix “.info”). To read the info, type 【Ctrl+u Alt+x info】 then type the info file's name.
What's the difference between {load-file, load, autoload, require}?
See: Emacs Lisp's Library System.
Emacs Customization
- Emacs init file
- Install Packages
- Install Package Manually
- Define Keys
- M-x customize
- What's Major Mode?
- What's Minor Mode?
- Set File to Open in a Major Mode
- Organize Init File
- Byte Compile Elisp
- What's Hook?
- Environment Variables in Emacs
- Set Default Window Size
- Font Setup
- Set Color Theme
- Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files
- Elisp: Determine OS, Emacs Version, Machine Host Name
- Elisp: Check If a {function, variable, feature} is Defined/Loaded
Patreon me $5. Ask me question on patreon