Learning by developing

...because practice teaches you

Opkg is a packet manager similar to APT-GET in Debian-based systems. It operates in a very easy way and makes really easy to install packages in Openwrt. Basic commands:


opkg help Gets the help for the packet manager with all the commands.
opkg update Gets the packages from the repositories.
opkg install package_name Install the package you indicate.
opkg remove package_name Remove the package you indicate.
opkg list | grep package Opkg list gives you the list of packages available in the repositories. Then you grep the package name you are looking for in order to filter it.
Opkg list-installed It gives you a list of all the packages installed in your router.


There are some other options which are used to force installation/removals of packages, force the use of configuration from the package(overwriting the already existing configuration files), etc., but I consider these I listed are the most used.


To get an idea of the usage of opkg, we should consider that, initially, our openwrt system does not have any package list downloaded. Thus if you try to install something it will not find it. Then we can find two different situations:

  1. When you want to install a package you have already downloaded and you know it runs with your openwrt version.
  2. When you want to download the last version of the package from the repository(it might be that you do not fulfill the dependencies on that packet, for instance, if you are using the trunk version of openwrt).


In the first situation, if you want to install the packet you have already downloaded, you will find that you can install it only if you did not update the opkg(the package-list files is removed every time the router is rebooted) or if there is no updates of this package. Opkg checks the checksum for every packet you install and compares it with the one stored in the package-list you download. So I recommend not to update the list of you are installing your already downloaded packages.


On the other hand, in the second scenario, you will first update the packages list “$ opkg update” and once updated you will do “$opkg install package_name” which will automatically install the package and all its dependencies. If you are using a trunk version of openwrt it might be that you cannot install because the kernel version has changed, for instance.


Once you have the packages installed you might need to remove some of the packages you installed due to the lack of space in the device. In order to do this just execute “$opkg remove package”. It might be that, if there’s not enough space in the drive, you may need to remove the executable by hand (probably from /bin or from /sbin) and then execute the opkg remove package.


When you want to check if a package is available, just do a “$ opkg list” to get the packages from the respositories(this needs to have already done an “$opkg update”) and then check the list. In my personal case I use always “grep” to filter the results “$ opkg list | grep PACKAGE-NAME”.


Last but not the least important is OPKG configuration file, which structure I am not going to explain, and which is placed in /etc/opkg.conf. I strongly recommend you to take a look to it.


That’s all for this article, I hope it was useful and you enjoyed.

Leave a Reply