Install dependencies

First of all, make sure to enable deb-src in /etc/apt/sources.list.d/ubuntu.sources (Types: deb deb-src), then run apt update.

Install build dependencies:

sudo apt build-dep -y emacs
sudo apt install libtree-sitter-dev

Clone the source repo

If you only want version 30:

git clone --depth 1 --branch emacs-30 git://git.savannah.gnu.org/emacs.git
cd ./emacs

If you want the entire emacs repo (beware, it's fairly large!):

git clone git://git.savannah.gnu.org/emacs.git
cd ./emacs
git worktree add ../emacs-30 origin/emacs-30

Configure

Run autogen:

./autogen.sh

Run ./configure:

CFLAGS="-march=native -pipe" \
    ./configure \
    --prefix=/opt/emacs30 \
    --with-cairo --with-libsystemd --with-modules \
    --with-tree-sitter \
    --with-x-toolkit=gtk3
  • Set --prefix to the desired install location
  • If you don't want X support, remove the --with-x-toolkit option, add --without-x --without-sound
  • See ./configure --help for other options
<!> Warning

The -march=native flag will tell gcc to make the resulting executable compatible only with the architecture of the current CPU. Remove (or modify) it if you need to redistribute the executable.

See also -march on the Gentoo wiki.

Build

make -j24
  • Adjust the -j option based on the number of cores on your machine

Install

make install

Run

/opt/emacs30/bin/emacs
/opt/emacs30/bin/emacsclient

Add to path:

PATH="/opt/emacs30/bin:${PATH}"

See also