17

Is it possible to force apt-get to download a multi-architecture binary of the library I want to install?

Or is apt-get not the right tool for this?

radj
  • 653

3 Answers3

13

@Tanasis's answer is correct, I have updated it for 2021 (Ubuntu 20.04 LTS) for arm64 and armhf.

  1. Add your desired architectures as follows:

    sudo dpkg --add-architecture armhf

    sudo dpkg --add-architecture arm64

  2. Create a new .list file in /etc/apt/sources.list.d:

    sudo touch /etc/apt/sources.list.d/arm-cross-compile-sources.list

  3. Add the default sources to that list with the architectures (armhf, arm64) prefixed as such:

    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal main restricted
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-updates main restricted
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal universe
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-updates universe
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal multiverse
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-updates multiverse
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-backports main restricted universe multiverse
    
  4. Update /etc/apt/sources.list to include your default architecture (if it doesn't already), otherwise apt will try to use your newly added architectures in those sources which may cause errors as it did with me. Add [arch=amd64] for each line in /etc/apt/sources.list as follows:

    deb [arch=amd64] http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse

  5. Run sudo apt update and make sure you get no errors

  6. Installing a package with the new architectures should be successful now:

    sudo apt install libasound2-dev:arm64

Bassam Helal
  • 231
  • 2
  • 4
  • When I install a package like this, it seems that dependencies are not automatically installed, eg. libflann-dev:arm64 : Depends: libhdf5-mpi-dev:arm64 but it is not going to be installed and this is transitive up the dependency chain. is this expected. – oarfish Jul 07 '23 at 11:36
8

First to enable multi-arch

dpkg --add-architecture <arch>

Now setup apt-sources to add the new repositories of the new architecture(if you need)

now update your sources.list

sudo apt-get update

Now you can install multi-arch packages via apt-get regularly but you have to specify which architecture you want to download

apt-get install package:architecture

example:

apt-get install gedit:i386
Maythux
  • 84,289
  • 1
    I ran dpkg --addarchitecture arm64 but I got an error dpkg: error: unknown option --add-architecture.

    I tried this and echoed foreign-architecture arm64 into /etc/dpkg/dpkg.cfg.d/multiarch. I ran sudo apt-get update but ran into more errors: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/precise/Release Unable to find expected entry 'main/binary-arm64/Packages' in Release file (Wrong sources.list entry or malformed file). What does this mean?

    – radj Mar 10 '14 at 02:25
  • Or there's no arm64 in the Ubuntu repositories? – radj Mar 10 '14 at 02:40
  • Never mind the dpkg --add-architecture just move on and try to install just apt-get install package:architecture – Maythux Mar 10 '14 at 06:17
  • Just to test this, I tried running sudo apt-get install vim:arm64 but got E: Unable to locate package vim:arm64. – radj Mar 11 '14 at 02:40
  • 2
    Any progress/fix on the arm64? – Tanasis Jan 11 '18 at 08:43
  • this worked well for me, thanks! i just wanted to add that to combine specifying architecture and version would be apt download package-name:arch=version – therightstuff Aug 14 '20 at 15:28
  • As a dreamer, I like the idea that dpkg --add-architecture arm64 would be enough to achieve a working configuration. But in practice, I had to manually add the sources.list entries like Tansis suggested, as well. – Jameson May 17 '21 at 18:53
7

For arm64 I am doing the following on the /etc/apt/sources.list:

Ubuntu 16.04 (xenial) example:

I mark all the current (default) repos as [arch=<current_os_arch>], e.g.

deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ xenial main restricted

And I added the following:

deb [arch=arm64] http://ports.ubuntu.com/ xenial main restricted

deb [arch=arm64] http://ports.ubuntu.com/ xenial-updates main restricted

deb [arch=arm64] http://ports.ubuntu.com/ xenial universe
deb [arch=arm64] http://ports.ubuntu.com/ xenial-updates universe

deb [arch=arm64] http://ports.ubuntu.com/ xenial multiverse
deb [arch=arm64] http://ports.ubuntu.com/ xenial-updates multiverse

deb [arch=arm64] http://ports.ubuntu.com/ xenial-backports main restricted universe multiverse

Not sure if this is the corrent fix, but at least it seems to be working.

Note: Don't forget to add foreign architecture: dpkg --add-architecture arm64

Tanasis
  • 476
  • 5
  • 8