Introduction
The subscription-manager command in Linux is specific to the RedHat Linux Distribution, which is used to manage subscriptions for RedHat services, just as the name suggests. Initially, it was only meant to be used in RedHat Linux only, as it is an enterprise distribution. But recently, other similar distributions like Fedora and CentOS can also use this command to connect to the RedHat Satellite or Foreman, and make use of the service, if they have already subscribed to it.
However, it is possible that you don’t have the command installed in your RedHat or other Linux distributions, in which case, you’ll not be able to execute the command and will see the error message saying “subscription-manager: command not found”. In this article, we’ll see how to fix this issue, and learn about a few uses in brief of the subscription-manager command.
Install subscription-manager in Linux
For the most part, simply just installing the subscription-manager package in Linux should fix the problem. It does not come preinstalled with most of the Linux distributions that support it other than RedHat.
In RedHat
In RedHat Linux, the subscription-manager command should already be installed by default. But if it isn’t so, for whatever reason, use the following commands in your terminal to install it:
$ sudo dnf makecache
$ sudo dnf install subscription-manager
The first line is very essential, as it will be required to update the repositories, while the second line will install the package. It is important to update the repositories as otherwise, you may fail to install any packages whatsoever.
If you’ve successfully been able to install the package without seeing any errors, then you should no longer see any error messages while trying to execute the subscription-manager command.
In Fedora
Installing it in Fedora Linux is just about the same, but here, we’ll be using the yum package manager instead of dnf. Use the following command in Fedora Linux to install the subscription-manager command:
$ sudo yum makecache
$ sudo yum install subscription-manager
The first line, as always, will update your repositories, and the second line will install the subscription-manager package.
In CentOS
Installing it in CentOS can be considered to be the exact same as RedHat Linux. However, their uses in these two distinctive systems are different. In RedHat Linux, the command will be used to register to installation, and everything else that requires. While in CentOS, you’d only be able to connect to the RedHat Satellite and or Foreman services, as there isn’t any need to register its installation anyway.
To install subscription-manager in CentOS, use the following commands:
$ sudo dnf makecache
$ sudo dnf install subscription-manager
You should now hopefully be able to use the subscription-manager command in your Linux machine.
Using the subscription-manager
In case you’re not really sure how to use the subscription-manager command, or what to use it for, we’ll be discussing these in brief here in this section.
Registering / unregistering RedHat Enterprise Linux
The most probable use case for the command is to register your installation of RedHat. To do this, you’d want use the following command:
$ subscription-manager register --username <name> --password <password>
Copy pasting the above on your terminal would cause a horrible mess, trust me. So don,t and hear me out first. The first part of the command involves the register option under the subscription-manager command. Here, you’ll need to provide the username you want to register the system for, and create a password for that user, for which the –username and the –password flags are used. In the above line, make sure to replace the <name> with the actual username you want to use, and the <password> with the password you’d like for the user to have.
That covers the registration part. Now what if you suddenly decide to unregister the user? You want to use this command for that:
$ subscription-manager unregister --username=<name>
In the above line, replace the <name> part with the username you want to unregister. Also, you’ll need to run the command as the root user, otherwise, it won’t work. Login as the root user and then use the above command to carry out the unregistration. However, if you have the sudo command installed and set up, then you can use this command instead to unregister the user without switching to the root user:
$ sudo subscription-manager unregister --username=<name>
As simple as that. But what if you need to keep track of multiple users at a time, having separate subscriptions?
Listing currently active Subscriptions
There are many other options and flags you can use under the subscription-manager command, in fact there’s a whole cheat sheet available in Google for all the options you can use. For now, there’s one other important command that you should know besides registering and unregistering RedHat Linux, which is to list all the currently active subscriptions under your machine. To see a list of all subscriptions, use the following command:
$ subscription-manager list -available
There’s one cool thing you could do with this as well. It’s not very helpful, but just in case you asked! That is, you can list the commands every time your terminal starts without needing to use the command again and again. If you’re using the Bourne Again Shell, doing this is as simple as adding the above command in the .bashrc file, located in your home directory. If you’re using some other shell than bourne again shell, then instead of .bashrc, it the file would be something else.
If you think you’d find this trick to be useful, then make sure not to mess it up and look out for how to do things first with .bashrc!
Conclusion
This pretty much covers getting your way round the subscription-manager: command not found error. There’s another common use for the subscription-manager command besides the ones mentioned, which is to enable or disable repositories in your RedHat installation. This is also a very crucial command, as some time along the line, you’ll be required to add repositories that contain certain packages you may need to install. So try to learn a bit about it. Redhat’s official website explains the procedure quite well, so waste no time and check it out, young lad!