# Elastic agent uninstall

**URL:** <https://discuss.elastic.co/t/elastic-agent-uninstall/349659>\
**Category:** Elastic Agent\
**Created:** [December 19, 2023, 2:19pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659 "2023-12-19T14:19:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![secsec](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@secsec](https://discuss.elastic.co/u/secsec)\
**Post date:** [December 19, 2023, 2:19pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/1 "2023-12-19T14:19:56Z")

</div>

Hello,

it seeemed to be simple but, im trying to uninstall elastic agent, but unfortunately no luck

root@elk:/opt/elastic-agent-8.11.2-linux-x86\_64# elastic-agent uninstall  
Error: can only be uninstalled by executing the installed Elastic Agent at: /usr/bin/elastic-agent  
For help, please see our troubleshooting guide at [Troubleshoot common problems | Fleet and Elastic Agent Guide [8.11] | Elastic](https://www.elastic.co/guide/en/fleet/8.11/fleet-troubleshooting.html)

root@elk:/opt/elastic-agent-8.11.2-linux-x86\_64# /usr/bin/elastic-agent uninstall  
Error: can only be uninstalled by executing the installed Elastic Agent at: /usr/bin/elastic-agent  
For help, please see our troubleshooting guide at [Troubleshoot common problems | Fleet and Elastic Agent Guide [8.11] | Elastic](https://www.elastic.co/guide/en/fleet/8.11/fleet-troubleshooting.html)  
root@elk:/opt/elastic-agent-8.11.2-linux-x86\_64# cd /usr/bin/

root@elk:/usr/bin# elastic-agent uninstall  
Error: can only be uninstalled by executing the installed Elastic Agent at: /usr/bin/elastic-agent  
For help, please see our troubleshooting guide at [Troubleshoot common problems | Fleet and Elastic Agent Guide [8.11] | Elastic](https://www.elastic.co/guide/en/fleet/8.11/fleet-troubleshooting.html)

root@elk:/usr/bin# sudo elastic-agent uninstall  
Error: can only be uninstalled by executing the installed Elastic Agent at: /usr/bin/elastic-agent  
For help, please see our troubleshooting guide at [Troubleshoot common problems | Fleet and Elastic Agent Guide [8.11] | Elastic](https://www.elastic.co/guide/en/fleet/8.11/fleet-troubleshooting.html)

I have also tried to stop elastic-agent server, but no luck

What im doing wrong?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 19, 2023, 2:26pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/2 "2023-12-19T14:26:27Z")

</div>

Hi @secsec  
Exactly how did you install Elastic Agent?

What command did you run?

Did you try the exact command giving in the documents [here](https://www.elastic.co/guide/en/fleet/8.11/uninstall-elastic-agent.html#_uninstall_on_macos_linux_and_windows)?

`sudo /opt/Elastic/Agent/elastic-agent uninstall`

---

<div class="post-metadata">

**Author:** ![secsec](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@secsec](https://discuss.elastic.co/u/secsec)\
**Post date:** [December 19, 2023, 2:27pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/3 "2023-12-19T14:27:51Z")

</div>

Thanks, but unfortunately no luck

root@elk:/opt/elastic-agent-8.11.2-linux-x86\_64# sudo /opt/Elastic/Agent/elastic-agent uninstall  
Error: can only be uninstalled by executing the installed Elastic Agent at: /usr/bin/elastic-agent  
For help, please see our troubleshooting guide at [Troubleshoot common problems | Fleet and Elastic Agent Guide [8.11] | Elastic](https://www.elastic.co/guide/en/fleet/8.11/fleet-troubleshooting.html)

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 19, 2023, 2:42pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/4 "2023-12-19T14:42:25Z")

</div>

You didn't answer the first question exactly how did you install?

Exactly what command did you run?

---

<div class="post-metadata">

**Author:** ![secsec](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@secsec](https://discuss.elastic.co/u/secsec)\
**Post date:** [December 19, 2023, 3:01pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/5 "2023-12-19T15:01:05Z")

</div>

I did this and now it is enrolled, topic can be closed

rm /etc/systemd/system/elastic-agent.service  
root@elk:/opt/Elastic# rm -r Agent

```
curl -L -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.11.2-linux-x86_64.tar.gz

```

tar xzvf elastic-agent-8.11.2-linux-x86\_64.tar.gz  
cd elastic-agent-8.11.2-linux-x86\_64  
sudo ./elastic-agent install --url=https://:8220   
--fleet-server-es=[https://localhost:9200](https://localhost:9200)   
--fleet-server-service-token=   
--fleet-server-policy=fleet-server-policy   
--certificate-authorities=/etc/elasticsearch/certs/new/ca.pem   
--fleet-server-es-ca=/etc/elasticsearch/certs/new/ca.pem   
--fleet-server-cert=/etc/elasticsearch/certs/new/elasticsearch.crt   
--fleet-server-cert-key=/etc/elasticsearch/certs/new/elasticsearch.key   
--fleet-server-port=8220

thanks

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 19, 2023, 3:04pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/6 "2023-12-19T15:04:48Z")

</div>

Yes, next time, you should run the correct command in the beginning, as I think you ended up in a half-uninstalled state.

Glad you got it fixed.

And yes, I have found when I have gotten in that state that re-installing you can get reset, and then when you want to uninstall next time, use the correct command.

---

<div class="post-metadata">

**Author:** ![optonpo](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@optonpo](https://discuss.elastic.co/u/optonpo)\
**Post date:** [January 5, 2024, 4:56pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/7 "2024-01-05T16:56:25Z")

</div>

It seems like a popular topic, but many threads are automatically closed without any elastic team response. One recommendation might be to document the uninstall warning/doc within the setup guide, especially for uninstall workflows that work differently than your other products.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [January 5, 2024, 5:09pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/8 "2024-01-05T17:09:37Z")

</div>

Hi @optonpo, Welcome to the community...

A closed topic does not mean that it is not searchable.

Yes, I think we should perhaps we could make the warning clearer... on the other hand, [the current documentation](https://www.elastic.co/guide/en/fleet/current/uninstall-elastic-agent.html#_uninstall_on_macos_linux_and_windows) is pretty specific on what command to run to uninstall.

---

<div class="post-metadata">

**Author:** ![optonpo](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@optonpo](https://discuss.elastic.co/u/optonpo)\
**Post date:** [January 5, 2024, 5:46pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/9 "2024-01-05T17:46:51Z")

</div>

not to split hairs, but:

1. 
  - searching unanswered threads isn't that helpful

2. 
  - the install docs are flush with troubleshooting links which do not mention/link to un/reinstall workflow

3. 
  - i've spent all morning trying to figure out why the uninstall command below does not work

> sudo /Library/Elastic/Agent/elastic-agent uninstall

I really do appreciate the intel that is available-. just frustrated--that's all.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [January 5, 2024, 5:53pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/10 "2024-01-05T17:53:32Z")

</div>

@optonpo

I have provided feedback to the Engineering team.... Mentioning this exact / your case... as well as the many others I have encountered.

They are looking at where / how to adjust the documentation to make it clearer... one of the engineers said he had done it himself...

> [@optonpo](#):
>
> I really do appreciate the intel that is available-. just frustrated--that's all.

Yes Exactly!! Understood...

BTW PR to get this fixed

> <https://github.com/elastic/ingest-docs/pull/796>
>
> Users sometimes run the agent uninstall command from the wrong location, causing… instability, so we need clear warnings in the docs.
> 
> Closes: #795 
> 
> \---
> 
> \*\*Update to agent \[uninstall instructions\](https://www.elastic.co/guide/en/fleet/current/uninstall-elastic-agent.html#uninstall-elastic-agent):\*\*
> 
> !\[Screenshot 2024-01-05 at 1 26 33 PM\](https://github.com/elastic/ingest-docs/assets/41695641/efed0670-d59b-4dea-8015-0bf320e1d958)
> 
> \---
> 
> \*\*Update to the agent \[\`uninstall\` command\](https://www.elastic.co/guide/en/fleet/current/elastic-agent-cmd-options.html#elastic-agent-uninstall-command):\*\*
> !\[Screenshot 2024-01-05 at 1 22 00 PM\](https://github.com/elastic/ingest-docs/assets/41695641/f8162d77-452b-4e62-9109-70c09da4fba6)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 2, 2024, 5:54pm UTC](https://discuss.elastic.co/t/elastic-agent-uninstall/349659/11 "2024-02-02T17:54:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
