误删codedeploy-agent文件夹后无法重新安装或卸载该组件的解决方案求助
/opt/codedeploy-agent The core problem here is that the RPM's pre-uninstall script is failing because it tries to stop the CodeDeploy agent via the init script, which depends on the deleted /opt/codedeploy-agent/ directory. We need to bypass that broken script first, then clean up remnants before doing a fresh install.
Step 1: Force Remove the Broken RPM
Since the pre-uninstall script is blocking the uninstall, we'll use rpm to remove the package without executing any pre/post scripts:
sudo rpm -e --noscripts codedeploy-agent-1.3.2-1902.noarch
(Make sure to use the exact package name from your error message—yours is codedeploy-agent-1.3.2-1902.noarch)
Step 2: Clean Up Leftover Files
Remove any remaining directories or files that might interfere with a fresh install:
sudo rm -rf /opt/codedeploy-agent/ sudo rm -rf /etc/init.d/codedeploy-agent sudo rm -rf /var/log/aws/codedeploy-agent/ sudo rm -rf /etc/codedeploy-agent/
Step 3: Reinstall the CodeDeploy Agent
Now we can perform a clean install. Choose one of these methods:
Method A: Using the Official Install Script
- Download the install script for your AWS region (replace
us-east-1with your actual region):sudo wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install - Make the script executable:
sudo chmod +x ./install - Run the install with the
--overrideflag to force installation (ignores cached version checks):sudo ./install auto --override
Method B: Install Directly from RPM
- Fetch the latest agent version number:
curl https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/LATEST_VERSION - Download the corresponding RPM (replace
<VERSION>with the output from the previous command):sudo wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/codedeploy-agent-<VERSION>.noarch.rpm - Install the RPM:
sudo rpm -ivh codedeploy-agent-<VERSION>.noarch.rpm
Verify the Installation
After installation, confirm the agent is running:
sudo service codedeploy-agent status
You should see a message indicating the agent is active and running.
内容的提问来源于stack exchange,提问作者Slim

