You can encounter error “Unable to locate package azure-functions-core-tools-4” while trying to install azure functions for local development of Azure Functions on your linux machine. It appears during following the official installation guide from Microsoft.
Root cause of “Unable to locate package azure-functions-core-4”
The reason for this error is below line of code from Azure documentation:
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'
It creates a below repository record in file /etc/apt/sources.list.d/dotnetdev.list
deb [arch=amd64] https://packages.microsoft.com/debian/20/prod focal main
Where “focal” is the name of the current Ubuntu version. In your situation, the current version might be different, but it doesn’t change the root cause. The Microsofts repository is not yet properly set up for the OS version that you’re using. You cannot possibly fix the repository at the side of Microsoft, but you can make an attempt to install the azure-functions-core-tools from the older repository.
Adding repository by hand
To install the software from the older repository you will have to add it by hand. In your favorite text editor, open file /etc/apt/sources.list.d/dotnetdev.list
Note that you will need root right to edit the file so open it with “sudo” prefix like this:
sudo vi /etc/apt/sources.list.d/dotnetdev.list
There should be one line with your current repository. Remove it. And then add a different repository with an OS version of your choosing. During this troubleshooting azure-functions-core-4 was succesfully installed from repo for Ubuntu Bionic. To add this repo paste the below line into the file:
deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic main
Retry the installation
At this point the installation should succeed. So run update and install the package once again:
matt@shell:~$ sudo apt-get update Hit:1 http://pl.archive.ubuntu.com/ubuntu focal InRelease Hit:2 http://pl.archive.ubuntu.com/ubuntu focal-updates InRelease Hit:3 http://pl.archive.ubuntu.com/ubuntu focal-backports InRelease Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease Hit:5 http://ppa.launchpad.net/nrbrtx/python2-stuff/ubuntu focal InRelease Hit:6 https://dl.google.com/linux/chrome/deb stable InRelease Hit:7 http://packages.microsoft.com/repos/code stable InRelease Get:8 https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic InRelease [4 002 B] Get:9 https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic/main amd64 Packages [262 kB] Fetched 266 kB in 1s (211 kB/s) Reading package lists... Done matt@shell:~$ sudo apt-get install azure-functions-core-tools-4 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libllvm11 linux-headers-5.13.0-41-generic linux-hwe-5.13-headers-5.13.0-41 linux-image-5.13.0-41-generic linux-modules-5.13.0-41-generic linux-modules-extra-5.13.0-41-generic Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: azure-functions-core-tools-4 0 upgraded, 1 newly installed, 0 to remove and 88 not upgraded. Need to get 142 MB of archives. After this operation, 0 B of additional disk space will be used. Get:1 https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic/main amd64 azure-functions-core-tools-4 amd64 4.0.4544-1 [142 MB] Fetched 142 MB in 18s (8 062 kB/s) Selecting previously unselected package azure-functions-core-tools-4. (Reading database ... 276029 files and directories currently installed.) Preparing to unpack .../azure-functions-core-tools-4_4.0.4544-1_amd64.deb ... Unpacking azure-functions-core-tools-4 (4.0.4544-1) ... Setting up azure-functions-core-tools-4 (4.0.4544-1) ... Telemetry --------- The Azure Functions Core tools collect usage data in order to help us improve your experience. The data is anonymous and doesn't include any user specific or personal information. The data is collected by Microsoft. You can opt-out of telemetry by setting the FUNCTIONS_CORE_TOOLS_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. matt@shell:~$
Above shows a successful installation. If this fails for you, play around with different versions. Find your release version with below command and google the name of the release version which precedes yours.
matt@shell:~$ lsb_release -cs