0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

開発用EC2インスタンスのユーザーデータ

0
Last updated at Posted at 2025-10-15

ubuntu24.04を使うときのユーザデータを作りました。
開発に必要なものは一通りいれてあります。

#!/bin/bash
set -euxo pipefail
export DEBIAN_FRONTEND=noninteractive

# ---- base packages ----
apt-get update
apt-get install -y \
  ca-certificates curl gnupg unzip \
  bash-completion git

# ---- Docker (official repo) ----
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
source /etc/os-release  # UBUNTU_CODENAME / VERSION_CODENAME を使う
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
https://download.docker.com/linux/ubuntu ${UBUNTU_CODENAME:-$VERSION_CODENAME} stable" \
  > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker
# EC2 デフォルトユーザーを docker グループへ
usermod -aG docker ubuntu || true

# ---- Node.js 22.x (NodeSource) ----
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs

# ---- pnpm (via Corepack) ----
# 署名の問題回避のため corepack を最新化 → pnpm を有効化&固定
npm install -g corepack@latest
corepack enable pnpm
corepack use pnpm@latest-10

# ---- AWS CLI v2 (official) ----
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip
unzip -q /tmp/awscliv2.zip -d /tmp
/tmp/aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
rm -rf /tmp/aws /tmp/awscliv2.zip

# ---- uv (Astral) 全ユーザー向けに /usr/local/bin へ ----
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="/usr/local/bin" sh

# ---- quick sanity ----
docker --version || true
node -v || true
pnpm -v || true
aws --version || true
uv --version || true
git --version || true

echo "✅ bootstrap finished"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?