how to install gcc-7-aarch64-linux-gnu on ubuntu 16.04

Solution 1:

I suggest you try to build the toolchain from sources. It's easy with an open source tool called crosstool-ng. This method requires more time, but allows configuration of the toolchain and usually works well even if you use some old or uncommon system.

In order to install ct-ng, follow the instructions here: https://crosstool-ng.github.io/docs/install/

The tool has a sample called aarch64-unknown-linux-gnu and it looks like the toolchain you need (to list all samples use ct-ng list-samples).

In order to initialize the configuration run:

ct-ng aarch64-unknown-linux-gnu

Then you can ct-ng nconfig to select specific options that you want to change. For example, you may want to change the version of GCC. You mentioned 7. So, select C compiler then Version of gcc and pick the one that you want. There should be several versions available.

When you're done selecting the options, run:

ct-ng build

In order to modify more things, for example the place where the toolchain shall be stored, you can use the docs: https://crosstool-ng.github.io/docs/configuration/