Home » Notes » How to Remove Service in Linux

How to Remove Service in Linux

Sometimes you may want to remove the Systemd service or at least make it unavailable for use. There is no sense to remove the unit file, cause after the next system update this file may be recovered.

The simplest way to remove a service in Linux - remove the package which provides this service. First, find the path to the unit file. You can use the systemctl status command:

sudo systemctl status nginx

Then, you can use the dpkg command to find a package which owns the file if you use Ubuntu. For example:

dpkg -S /lib/systemd/system/nginx.service

After this, you can remove the package:

sudo apt remove nginx

If you don't want to delete the package or it is impossible, cause the service is provided by one of the system packages, you can mask the service. Systemd wouldn't start masked packages on the system startup even if they are added to the system autostart. And, of course, you can't start them manually. Use the mask command to make the package unavailable. For example:

sudo systemctl mask nginx

After this, you can check the status of the service and ensure that it has been masked:

sudo systemctl status nginx

Also, you will get an error when trying to start the service:

sudo systemctl start nginx

Use the unmask command to disable masking and make the service available for using:

sudo systemctl unmask nginx

Now, you have learned how to remove service in Linux. As you can see it is pretty straightforward. Read about services in detail in this article.

Rate the Article

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...
Creative Commons License
The article is distributed under Creative Commons ShareAlike 4.0 license. Link to the source is required .

Leave a Comment