Ubuntu includes GNU tar, which recognizes the format by itself! One command works with any supported compression method, per the manual.
tar xf archive.tar.xz
tar xf archive.tar.gz
tar xf archive.tar
etc. If tar gives a Cannot exec error, you may need to sudo apt install xz-utils first.