For those hating the Flatpak and Snap packages, here’s how to compile GNU Emacs editor (v27.2 tested) from the source tarball while the Kevin Kelley’s PPA seems NOT to be updated anymore.
Before getting started, it’s recommended to remove old Emacs (if any) by running command in terminal (Ctrl+Alt+T):
sudo apt remove --autoremove emacs emacs-common
Install build dependencies:
Firstly, press Ctrl+Alt+T on keyboard to open a terminal window. When it opens, run command to install build-essential
package:
sudo apt install build-essential
Next, search for and open ‘Software & Updates‘ from Activities overview screen. In the first tab, enable ‘Source code’ by ticking the checkbox.
Finally, refresh package cache and use apt build-dep
command to install build depends:
sudo apt update && sudo apt build-dep emacs
Download Emacs source tarball:
The source tarball is available to download at the link below. So far the latest is ’emacs-27.2.tar.xz’:
Next, extract the tarball. Right-click on source folder and select ‘Open in Terminal‘ to open a terminal with that folder as working directory.
Build & Install Emacs:
After opening source folder in terminal, run autogen.sh script to generate configure scripts:
./autogen.sh
And, configure the source via command:
./configure
If no error outputs, build Emacs via command:
make bootstrap -j4
NOTE: here I use -j4
to start 4 threads to speed up make process. Depends on how many CPU cores in your machine, you may use -j8
or -j16
or just skip it.
When everything’s done successfully, install the editor via command:
sudo make install
Finally, try launching the app via emacs command.
Create app shortcut icon:
By default, it installs the executable binary as ‘/usr/local/bin/emacs‘. However, it does not create app icon for launching from start menu.
To create one, run command in terminal:
sudo gedit /usr/share/applications/emacs.desktop
It will create and opens the config file in Gedit text editor. When it opens, paste the following lines and save it.
[Desktop Entry]
Version=1.0
Name=Emacs (GUI)
GenericName=Text Editor
Comment=GNU Emacs is an extensible, customizable text editor - and more
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
TryExec=/usr/local/bin/emacs
Exec=/usr/local/bin/emacs %F
Icon=emacs
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs
Keywords=Text;Editor;
Just like the package in Ubuntu repository, you may also create a shortcut icon for launching Emacs in command line:
sudo gedit /usr/share/applications/emacs-term.desktop
Paste the previous content but change the “Name“, “Exec” (use /usr/local/bin/emacs -nw %F
instead), and set “Terminal = true”.
When everything’s done, search for and open ‘Emacs’ from Activities overview and enjoy!
How to Remove Emacs that compiled from source:
Until you removed the source folder, you may run command (open folder in terminal) in terminal from that folder to uninstall Emacs:
sudo make uninstall
If you’ve already removed the source. You may also re-download it, extract, open in terminal, and run the previous command to do the job.
And, remove the app shortcuts using command:
sudo rm /usr/share/applications/emacs*.desktop
That’s all. Enjoy!