{"id":36512,"date":"2021-12-27T14:59:26","date_gmt":"2021-12-27T14:59:26","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=36512"},"modified":"2021-12-27T14:59:26","modified_gmt":"2021-12-27T14:59:26","slug":"compile-gnu-emacs-source-ubuntu","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2021\/12\/compile-gnu-emacs-source-ubuntu\/","title":{"rendered":"How to Compile GNU Emacs from Source in Ubuntu 20.04 \/ 21.10"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" class=\"alignleft size-thumbnail wp-image-36513\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/emacs-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>For those hating the Flatpak and Snap packages, here&#8217;s how to compile GNU Emacs editor (v27.2 tested) from the source tarball while the <a href=\"https:\/\/launchpad.net\/~kelleyk\/+archive\/ubuntu\/emacs\" rel=\"noopener\" target=\"_blank\">Kevin Kelley&#8217;s PPA<\/a> seems NOT to be updated anymore.<\/p>\n<p>Before getting started, it&#8217;s recommended to <b>remove old Emacs (if any)<\/b> by running command in terminal (Ctrl+Alt+T):<\/p>\n<pre>sudo apt remove --autoremove emacs emacs-common<\/pre>\n<h3>Install build dependencies:<\/h3>\n<p>Firstly, press <b>Ctrl+Alt+T<\/b> on keyboard to open a terminal window. When it opens, run command to install <code>build-essential<\/code> package:<\/p>\n<pre>sudo apt install build-essential<\/pre>\n<p>Next, search for and open &#8216;<b>Software &#038; Updates<\/b>&#8216; from <i>Activities<\/i> overview screen. In the first tab, <b>enable &#8216;Source code&#8217;<\/b> by ticking the checkbox.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/enable-source.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/enable-source-600x291.webp\" alt=\"\" width=\"600\" height=\"291\" class=\"aligncenter size-large wp-image-36514\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/enable-source-600x291.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/enable-source-300x145.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/enable-source-768x372.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/enable-source.webp 1012w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Finally, refresh package cache and use <code>apt build-dep<\/code> command to install build depends:<\/p>\n<pre>sudo apt update && sudo apt build-dep emacs<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/apt-emacs-deps.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/apt-emacs-deps.png\" alt=\"\" width=\"600\" height=\"297\" class=\"aligncenter size-full wp-image-36515\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/apt-emacs-deps.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/apt-emacs-deps-300x149.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>Download Emacs source tarball:<\/h3>\n<p>The source tarball is available to download at the link below. So far the latest is &#8217;emacs-27.2.tar.xz&#8217;:<\/p>\n<div class=\"wp-block-buttons aligncenter\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background\" href=\"http:\/\/ftp.gnu.org\/gnu\/emacs\/\" target=\"_blank\" rel=\"noreferrer noopener\">Download GNU Emacs<\/a><\/div>\n<\/div>\n<p>Next, extract the tarball. Right-click on source folder and select &#8216;<b>Open in Terminal<\/b>&#8216; to open a terminal with that folder as working directory.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/open-emacs-terminal.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/open-emacs-terminal-600x400.webp\" alt=\"\" width=\"600\" height=\"400\" class=\"aligncenter size-large wp-image-36516\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/open-emacs-terminal-600x400.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/open-emacs-terminal-300x200.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/open-emacs-terminal-768x511.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/open-emacs-terminal.webp 1000w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>Build &#038; Install Emacs:<\/h3>\n<p>After opening source folder in terminal, run autogen.sh script to generate configure scripts:<\/p>\n<pre>.\/autogen.sh<\/pre>\n<p>And, configure the source via command:<\/p>\n<pre>.\/configure<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/configure-emacs.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/configure-emacs.png\" alt=\"\" width=\"600\" height=\"209\" class=\"aligncenter size-full wp-image-36517\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/configure-emacs.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/configure-emacs-300x105.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>If no error outputs, build Emacs via command:<\/p>\n<pre>make bootstrap -j4<\/pre>\n<p><b>NOTE:<\/b> here I use <code>-j4<\/code> to start 4 threads to speed up make process. Depends on how many CPU cores in your machine, you may use <code>-j8<\/code> or <code>-j16<\/code> or just skip it.<\/p>\n<p>When everything&#8217;s done successfully, install the editor via command:<\/p>\n<pre>sudo make install<\/pre>\n<p>Finally, try launching the app via <b>emacs<\/b> command.<\/p>\n<h3>Create app shortcut icon:<\/h3>\n<p>By default, it installs the executable binary as &#8216;<b>\/usr\/local\/bin\/emacs<\/b>&#8216;. However, it does not create app icon for launching from start menu.<\/p>\n<p>To create one, run command in terminal:<\/p>\n<pre>sudo gedit \/usr\/share\/applications\/emacs.desktop<\/pre>\n<p>It will create and opens the config file in Gedit text editor. When it opens, paste the following lines and save it.<\/p>\n<pre style=\"background:none;\">[Desktop Entry]\r\nVersion=1.0\r\nName=Emacs (GUI)\r\nGenericName=Text Editor\r\nComment=GNU Emacs is an extensible, customizable text editor - and more\r\nMimeType=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++;\r\nTryExec=\/usr\/local\/bin\/emacs\r\nExec=\/usr\/local\/bin\/emacs %F\r\nIcon=emacs\r\nType=Application\r\nTerminal=false\r\nCategories=Utility;Development;TextEditor;\r\nStartupWMClass=Emacs\r\nKeywords=Text;Editor;<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/create-emacs-shortcut.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/create-emacs-shortcut-600x409.webp\" alt=\"\" width=\"600\" height=\"409\" class=\"aligncenter size-large wp-image-36518\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/create-emacs-shortcut-600x409.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/create-emacs-shortcut-300x205.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/create-emacs-shortcut-768x524.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/create-emacs-shortcut.webp 861w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Just like the package in Ubuntu repository, you may also create a shortcut icon for launching Emacs in command line:<\/p>\n<pre>sudo gedit \/usr\/share\/applications\/emacs-term.desktop<\/pre>\n<p>Paste the previous content but change the &#8220;<b>Name<\/b>&#8220;, &#8220;<b>Exec<\/b>&#8221; (use <code>\/usr\/local\/bin\/emacs -nw %F<\/code> instead), and set &#8220;Terminal = true&#8221;.<\/p>\n<p>When everything&#8217;s done, search for and open &#8216;Emacs&#8217; from <i>Activities<\/i> overview and enjoy!<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/launch-emacs.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/launch-emacs.jpg\" alt=\"\" width=\"503\" height=\"261\" class=\"aligncenter size-full wp-image-36519\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/launch-emacs.jpg 503w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/12\/launch-emacs-300x156.jpg 300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/a><\/p>\n<h3>How to Remove Emacs that compiled from source:<\/h3>\n<p>Until you removed the source folder, you may run command (<i>open folder in terminal<\/i>) in terminal from that folder to uninstall Emacs:<\/p>\n<pre>sudo make uninstall<\/pre>\n<p>If you&#8217;ve already removed the source. You may also re-download it, extract, open in terminal, and run the previous command to do the job.<\/p>\n<p>And, remove the app shortcuts using command:<\/p>\n<pre>sudo rm \/usr\/share\/applications\/emacs*.desktop<\/pre>\n<p>That&#8217;s all. Enjoy!<\/p>","protected":false},"excerpt":{"rendered":"<p>For those hating the Flatpak and Snap packages, here&#8217;s how to compile GNU Emacs editor (v27.2 tested) from the source tarball while the Kevin Kelley&#8217;s PPA seems NOT to be updated anymore. Before getting started, it&#8217;s recommended to remove old Emacs (if any) by running command in terminal (Ctrl+Alt+T): sudo apt remove &#8211;autoremove emacs emacs-common [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":36513,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[247],"class_list":["post-36512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-editor"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/36512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=36512"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/36512\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/36513"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=36512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=36512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=36512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}