Ubuntu Server 22.04 LTS EC2实例安装AWS CodeDeploy Agent遇Ruby版本问题求助
在Ubuntu Server 22.04 LTS的EC2实例上安装AWS CodeDeploy Agent的解决方案
问题场景
在Ubuntu Server 22.04 LTS的Amazon EC2实例上,按照官方文档执行以下命令安装AWS CodeDeploy Agent时:
sudo apt update sudo apt install ruby-full sudo apt install wget wget https://aws-codedeploy-ap-south-1.s3.ap-south-1.amazonaws.com/latest/install chmod +x ./install sudo ./install auto
执行最后一条命令报错,提示当前Ruby版本为3.0.2,需要2.x版本。
错误信息
I, [2022-11-25T20:22:45.262298 #4303] INFO -- : Starting Ruby version check. E, [2022-11-25T20:22:45.262740 #4303] ERROR -- : Current running Ruby version for root is 3.0.2, but Ruby version 2.x needs to be installed. E, [2022-11-25T20:22:45.262959 #4303] ERROR -- : If you already have the proper Ruby version installed, please either create a symlink to /usr/bin/ruby2.x, E, [2022-11-25T20:22:45.263173 #4303] ERROR -- : or run this install script with right interpreter. Otherwise please install Ruby 2.x for root user. E, [2022-11-25T20:22:45.263378 #4303] ERROR -- : You can get more information by running the script with --help option.
解决方法
方法1:使用rbenv安装Ruby 2.x并指定运行脚本
- 安装rbenv及依赖:
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
- 配置环境变量(添加到~/.bashrc):
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
- 安装Ruby 2.7.x(兼容CodeDeploy Agent的最新2.x版本):
rbenv install 2.7.8 rbenv global 2.7.8
- 重新运行安装脚本:
sudo ./install auto
方法2:手动下载并安装CodeDeploy Agent的deb包
Ubuntu 22.04可以直接使用AWS提供的适配deb包(以ap-south-1区域为例):
wget https://aws-codedeploy-ap-south-1.s3.ap-south-1.amazonaws.com/latest/codedeploy-agent_all.deb sudo dpkg -i codedeploy-agent_all.deb
如果出现依赖问题,修复后启动服务:
sudo apt-get install -f sudo systemctl start codedeploy-agent sudo systemctl enable codedeploy-agent
方法3:临时修改安装脚本的Ruby版本检查(不推荐长期使用)
编辑install脚本,找到Ruby版本检查的代码块,将版本判断从2.x改为允许3.x:
nano install
找到类似if ! ruby_version.match?(/2\./)的行,修改为if ! ruby_version.match?(/2\.|3\./),保存后重新运行:
sudo ./install auto
内容的提问来源于stack exchange,提问作者Debaditya Bhar
相关产品推荐
相关产品推荐

