Sửa lỗi unable to locate package trên ubuntu

Việc cài đặt phần mềm trên hệ thống Linux thường dễ dàng — thường không yêu cầu nhiều hơn một lệnh trên terminal. Nhưng lần đầu tiên bạn cố gắng thêm một kho lưu trữ (repository) mới, bạn có thể gặp phải lỗi “add-apt-repository: command not found”. Bài viết dưới đây sẽ giải thích điều đó có nghĩa là gì và bạn có thể làm gì để khắc phục.

Tại sao xuất hiện thông báo “add-apt-repository: command not found”?

Phần mềm thường được quản lý trên các hệ thống Linux dựa trên Debian thông qua APT (Advanced Package Tool, tạm dịch là Công cụ Gói Nâng cao). Bạn có thể sử dụng công cụ này để tìm kiếm, cài đặt, cập nhật hoặc xóa các gói khỏi hệ thống của người dùng. Các gói này được lưu trữ trong kho lưu trữ (repository), bộ sưu tập phần mềm khổng lồ trên các hệ thống từ xa.

Để cài đặt phần mềm từ kho lưu trữ bằng tài khoản người dùng của mình, hãy gõ lệnh:

sudo apt install package-name

Và loại bỏ các gói đã cài đặt, dùng lệnh:

sudo apt remove package-name

Hoặc:

sudo apt purge package-name

Các hệ thống dựa trên Debian (bao gồm cả Ubuntu) sẽ đi kèm với các kho lưu trữ mặc định, nơi bạn có thể tìm thấy phần mềm phổ biến nhất.

Để xem hệ thống hiện đang được định cấu hình để sử dụng kho lưu trữ nào, gõ lệnh:

cat /etc/apt/sources.list

Sửa lỗi unable to locate package trên ubuntu

Nếu bạn muốn sử dụng công cụ APT để cài đặt phần mềm không có sẵn trong kho lưu trữ mặc định, bạn sẽ cần thêm kho mới bằng cách sử dụng lệnh sudo add-apt-repository, cập nhật hệ thống và sau đó cài đặt gói.

Ví dụ, dể cài đặt trình đọc QuiteRSS, bạn sẽ nhập:

sudo add-apt-repository ppa:quiterss/quiterss

Nếu nhận được thông báo lỗi “sudo: add-apt-repository: command not found”, có nghĩa là gói chưa được cài đặt trên hệ thống của bạn.

Sửa lỗi unable to locate package trên ubuntu

Cách khắc phục

Khi một gói bạn cần chưa được cài đặt, bạn có thể thử cài đặt nó bằng APT. Tuy nhiên, nếu bạn thử cài đặt add-apt-repository theo cách này, bạn sẽ thấy thêm một lỗi: “Unable to locate package add-apt-repository” (Không thể định vị gói add-apt-repository).

Sửa lỗi unable to locate package trên ubuntu

Điều này là do add-apt-repository được bao gồm như một phần của gói lớn hơn được gọi là software-properties-common (phần mềm-thuộc tính-chung), gói này cũng chứa các tệp chung cho các thuộc tính phần mềm.

Để cài đặt phần mềm-thuộc tính-chung, dùng lệnh:

sudo apt install software-properties-common

Giờ đây khi bạn đã có thể thêm một kho lưu trữ bằng cách sử dụng add-apt-repository.

Kết luận

Sau khi cài đặt gói phần mềm-thuộc tính-chung, bạn có thể thêm bao nhiêu kho tùy thích. Tuy nhiên, bạn cũng nên lưu ý rằng không phải tất cả các kho lưu trữ đều an toàn và mặc dù Linux có danh tiếng xuất sắc về bảo mật và khả năng chống phần mềm độc hại, nó không bất khả xâm phạm trước các cuộc tấn công. Bởi vậy, hãy kiểm tra cẩn thận trước khi thêm kho.

PS . Nếu bạn thích bài viết này về cách sửa chữa các package bị hỏng trên Ubuntu 16.04 và Debian 9, hãy chia sẻ nó với bạn bè của bạn trên các mạng xã hội bằng cách sử dụng các nút bên dưới hoặc đơn giản là để lại nhận xét. Cảm ơn.

Sometimes, when installing a package on Ubuntu using the APT package manager, you might bump into the error “E: Unable to locate package“. This might seem a little confusing especially when you have checked your internet connection and are sure everything is in place.

In this tutorial, we will explore the reasons why this “E: Unable to locate package” error manifests and possible solutions to remedy it in Ubuntu.

Table of Contents

1. Check Package Spelling/Case-Insensitive in Ubuntu

A typo in the name of the package may result in this error. In fact, this is the first thing you should check. For example, to install the Mariadb server on Ubuntu, if you type mariabd-server instead of mariadb-server, you will get the error.

$ sudo apt install mariabd-server

Sửa lỗi unable to locate package trên ubuntu
E: Unable to locate package Error

In addition, typing a package name in uppercase characters will also contribute to this error. For example, typing MARIADB-SERVER will result in the same error.

Therefore, it is always advisable to check the spelling of the software package in case you run into this error. In addition, ensure that the case is right (mostly lowercase).

2. Update Local Package Index in Ubuntu

If there’s no typo in the package name, and you are still experiencing the error, you might want to consider refreshing the local package index. This is especially true if you are using a fresh installation of Ubuntu which ships with an empty cache.

To update the local cache, run the apt update command as follows.

$ sudo apt update Once the cache is updated, the APT package manager will reference the freshly built local cache and finally install the package in question from the default Ubuntu repository.

Another approach you can take is to check the availability of the package on Ubuntu Packages Search, which is a website that displays information about all packages hosted on the Ubuntu Package archive.

It allows you to browse through a list of packages available for any Ubuntu release and contained in any of the four main repositories provided by Ubuntu [main, multiverse, restricted, and universe].

Before you do so, it’s prudent to, first of all, check what Ubuntu release you are using.

$ hostnamectl OR $ lsb_release -a From the output provided, you can see that we are running Ubuntu 22.04, Jammy JellyFish.

Sửa lỗi unable to locate package trên ubuntu
Check Ubuntu Release

Now, head over to the Keyword search box and type in the name of the package. Next, select your distribution. If you are not sure which repository the package is contained in, set the ‘Section’ option to ‘any’ and click ‘Search’.

In this example, we are searching for the availability of the Flameshot package.

Sửa lỗi unable to locate package trên ubuntu
Ubuntu Package Search

If the package is available, you will get a match. In our case, we got an exact match detailing the OS release, a simple description of the software package, and the repository that provides it (Universe).

A positive result grants you the go-ahead to proceed with the installation of the package. If the package cannot be found, then it is not yet available in the default repositories and cannot the installed directly using the APT package manager.

Sửa lỗi unable to locate package trên ubuntu
Ubuntu Package Information

4. Install Missing Ubuntu Repositories

As we have already seen, Ubuntu provides 4 repositories –

  • Main
  • Multiverse
  • Restricted
  • Universe

Each of these provides a set of packages for download on your system. If you are on an older system that is missing any of these repositories, you can add them as follows.

$ sudo add-apt-repository main $ sudo add-apt-repository multiverse $ sudo add-apt-repository restricted $ sudo add-apt-repository universe Once you have added the repository, ensure to update the local cache to notify your system of the new packages provided by it.

$ sudo apt update Now give it another try and, this time, you should be able to install the package without an issue.

5. Check Your Active Ubuntu Release

There are two major releases provided by Ubuntu. The LTS (Long Term Support) is a release that is supported or maintained for 5 years. Support includes bug fixes, patches, and security updates. The latest LTS release is Ubuntu 22.04.

The other release is the standard or interim release, which is supported for nine months. At the moment, the latest standard release is Ubuntu 23.04.

When a release reaches end-of-life (EOL) it stops being supported by Canonical and no longer receives patches, updates, and new software.

To check if you are running an active Ubuntu release, run the following command.

$ hwe-support-status --verbose The command provides the following output. The last sentence will tell if your system is supported or not. In our case, we are running Ubuntu 22.04 which will be supported until April 2027.

Sửa lỗi unable to locate package trên ubuntu
Check How Long Ubuntu Supported

If your system is not supported, you will most certainly encounter the error.

Conclusion

These are some of the possible solutions to address the “Unable to locate package” Error on Ubuntu. If you are still experiencing challenges installing a package, consider trying to install it from Snap or flatpak.

You can also install packages from third-party repositories known as PPAs (Personal Package Archive). This is a repository that provides software packages maintained by individuals or groups of developers. These packages are not avaiable in Official Ubuntu repositories.

And this draws this guide to a close. We have seen various ways that you can use to troubleshoot the “Unable to locate package” error in Ubuntu.