# Elastic agent fails to install on Centos 7

**URL:** <https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260>\
**Category:** Elastic Agent\
**Created:** [April 3, 2023, 11:04pm UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260 "2023-04-03T23:04:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sblack](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sblack](https://discuss.elastic.co/u/sblack)\
**Post date:** [April 3, 2023, 11:04pm UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/1 "2023-04-03T23:04:48Z")

</div>

Hi,

I am getting the following error message when attempting to install Fleet agent:

```auto
Installed as a system package, installation will not be altered.
Error: failed to execute enroll command: fork/exec /usr/bin/elastic-agent: no such file or directory

```

The machine previously had an older version 7.15.2 and we tried to update via the Kibana, but it failed to update.

I tried manually attempt to update and that didn't work. So I removed the old installation and purged all remnants of the previous install, but still get the above error.

Any suggestions on how I get pass this error?

Regards,  
Simon

---

<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:** [April 4, 2023, 1:05am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/2 "2023-04-04T01:05:37Z")

</div>

Hi @sblack Welcome to the Community!

> [@sblack](#):
>
> I tried manually attempt to update and that didn't work. So I removed the old installation and purged all remnants of the previous install, but still get the above error.

Where / How did you install the Elastic Stack: Self Managed or Elastic Cloud?

Are you trying to do Fleet Managed Agent or Standalone Agent?

How did you install the old elastic agent?

How did you remove the old agent?

And exactly how did you try to install the new elastic agent?

---

<div class="post-metadata">

**Author:** ![sblack](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sblack](https://discuss.elastic.co/u/sblack)\
**Post date:** [April 4, 2023, 2:01am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/3 "2023-04-04T02:01:23Z")

</div>

Hi @stephenb,

Apologies, I should have added more specific detail.

The installation is self-managed (version 8.5.3). It is a small instance in our QA environment. Elastic/Kibana/Fleet agent server is installed on a Linux machine (Centos 7) and the agent was installed on separate Linux machine (also Centos 7). There are other agents installed on other machines (also Centos) and these installed without error. Only on the machine which previously had an older version of Fleet agent (7.15.2) is there a problem.

Older agent was installed as a Fleet Managed Agent. This was when we were running Elastic-Kibana version 7.15.2. This would have been installed as follows:

```auto
 curl -L -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.15.2-linux-x86_64.tar.gz
  tar xzvf elastic-agent-7.15.2-linux-x86_64.tar.gz
  cd elastic-agent-7.15.2-linux-x86_64
  sudo ./elastic-agent install -f --url=http://<agent hostname>:8220 --enrollment-token=<token>== --insecure

```

We then upgraded the stack to 8.5.3. After the upgrade, we attempted to update the agent via Kibana and as I mentioned above that didn't work.

To uninstall agent, ran the following:

```auto
sudo ./elastic-agent uninstall

```

Downloaded the new agent tar ball, extracted, added new agent via Kibana and ran the following:

```auto
 sudo ./elastic-agent install --url=http://<agent hostname>:8220 --enrollment-token=<token>== --insecure

```

This threw the error:

```auto
Installed as a system package, installation will not be altered.
Error: failed to execute enroll command: fork/exec /usr/bin/elastic-agent: no such file or directory

```

Searching the file system, I noticed there were still remnants of previous installation, so I removed all that:

```auto
sudo rm -rf /usr/share/elastic-agent/
sudo rm /usr/bin/elastic-agent*
sudo rm /usr/lib/systemd/system/elastic-agent.service
sudo rm /etc/rc.d/init.d/elastic-agent
sudo rm -r /etc/elastic-agent
sudo rm -r /var/lib/elastic-agent

```

Maybe the uninstall wasn't successful. But I would have thought that removing the above would clear the installation.

Regards,  
Simon

---

<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:** [April 4, 2023, 2:59am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/4 "2023-04-04T02:59:31Z")

</div>

> [@sblack](#):
>
> `sudo ./elastic-agent uninstall`

Yup that was your first error... 🙂

[Per the docs](https://www.elastic.co/guide/en/fleet/7.15/uninstall-elastic-agent.html#uninstall-elastic-agent), running from the local directory does not uninstall correctly / everything.

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

Try this above command after the installation fails and see what happens.

Then try to re-install

---

<div class="post-metadata">

**Author:** ![sblack](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sblack](https://discuss.elastic.co/u/sblack)\
**Post date:** [April 4, 2023, 3:13am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/5 "2023-04-04T03:13:40Z")

</div>

Thanks @stephenb

`/opt/Elastic/Agent/` is not present anymore. Probably got removed with the (incorrect) uninstall? 😧

Is there any way back in this case?

---

<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:** [April 4, 2023, 3:48am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/6 "2023-04-04T03:48:50Z")

</div>

Did you try to install...

Let it fail...

Then try the uninstall command

---

<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:** [April 4, 2023, 3:53am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/7 "2023-04-04T03:53:22Z")

</div>

Did you clean `/opt/Elastic` ohh I see it's gone..

---

<div class="post-metadata">

**Author:** ![sblack](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sblack](https://discuss.elastic.co/u/sblack)\
**Post date:** [April 4, 2023, 4:05am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/8 "2023-04-04T04:05:04Z")

</div>

> [@stephenb](#):
>
> sudo /opt/Elastic/Agent/elastic-agent uninstall

I can't recall removing the `/opt/Elastic/Agent` directory. I think the first uninstall did that.

---

<div class="post-metadata">

**Author:** ![sblack](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sblack](https://discuss.elastic.co/u/sblack)\
**Post date:** [April 4, 2023, 4:09am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/9 "2023-04-04T04:09:31Z")

</div>

I wasn't able to install the 8.5.3 agent to get back the `/opt/Elastic/Agent` directory.

But I was able to successfully install the 7.15.2 agent (and then have it fail - I passed some bogus token). This created the `/opt/Elastic/Agent` directory`. Then successfully uninstall it.

Then tried installing 8.5.3 and get the same error message.

I am going to try installing the 7.15.2 agent again and try updating to 8.5.3.

---

<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:** [April 4, 2023, 4:20am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/10 "2023-04-04T04:20:07Z")

</div>

Okay, you're making progress. I went through this before but I can't remember all my step.

That was the right thing to do to reinstall the 7.15 and then remove it properly... I thought that worked for me.

Somewhere along the line try this command

`sudo /bin/systemctl daemon-reload`

---

<div class="post-metadata">

**Author:** ![sblack](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sblack](https://discuss.elastic.co/u/sblack)\
**Post date:** [April 4, 2023, 4:21am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/11 "2023-04-04T04:21:19Z")

</div>

That worked.

I installed 7.15.2 and had it enrol. Then via Kibana, upgraded the agent.

---

<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:** [May 2, 2023, 4:22am UTC](https://discuss.elastic.co/t/elastic-agent-fails-to-install-on-centos-7/329260/12 "2023-05-02T04:22:15Z")

</div>

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