There are two ways to install ZFS on Ubuntu: using jonathonf's PPA and compiling from sources.
Ubuntu repo
Ubuntu comes with the ZFS package, but usually it is a bit outdated:
sudo apt install zfsutils-linux
jonathonf's PPA
To install the latest ZFS version, add jonathonf's PPA:
sudo add-apt-repository ppa:jonathonf/zfs
And then install ZFS and zfs-dkms
to update ZFS Linux kernel modules:
sudo apt install zfsutils-linux zfs-dkms
Compile from sources
You can also compile and install ZFS from sources, but you will need to re-compile ZFS Linux kernel modules whenever Linix kernel is updated.
Install dependencies:
sudo apt install build-essential autoconf automake libtool gawk alien fakeroot dkms libblkid-dev uuid-dev libudev-dev libssl-dev zlib1g-dev libaio-dev libattr1-dev libelf-dev linux-headers-$(uname -r) python3 python3-dev python3-setuptools python3-cffi libffi-dev python3-packaging git
Compile ZFS:
git clone https://github.com/openzfs/zfs
cd ./zfs
git checkout master
sh autogen.sh
./configure
make -s -j$(nproc)
Unmount existing ZFS datasets and export pools:
sudo zfs unmount -a
sudo zpool export -a
sudo systemctl stop zfs-send
Unload existing ZFS modules:
sudo ./scripts/zfs.sh -u
Install newly compiled ZFS:
sudo make install
sudo ldconfig
sudo depmod
Load freshly built Linux modules:
sudo ./scripts/zfs.sh
And make sure that ZFS services are enabled:
sudo systemctl enable zfs.target zfs-import.target zfs-mount.service zfs-import-cache.service zfs-import-scan.service