Skip to content

Commit 29bedd3

Browse files
authored
Merge pull request #772 from github/devm33/install
Add installation script
2 parents 44a9767 + 791b545 commit 29bedd3

File tree

2 files changed

+114
-5
lines changed

2 files changed

+114
-5
lines changed

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,41 @@ If you have access to GitHub Copilot via your organization or enterprise, you ca
3939

4040
### Installation
4141

42-
Install globally with npm:
42+
Install with [WinGet](https://github.com/microsoft/winget-cli) (Windows):
4343

4444
```bash
45-
npm install -g @github/copilot
45+
winget install GitHub.Copilot
4646
```
4747

48-
Install with [Homebrew](https://formulae.brew.sh/cask/copilot-cli):
48+
Install with [Homebrew](https://formulae.brew.sh/cask/copilot-cli) (macOS and Linux):
4949

5050
```bash
5151
brew install copilot-cli
5252
```
5353

54-
Install with [WinGet](https://github.com/microsoft/winget-cli):
54+
Install with the install script (macOS and Linux):
5555

5656
```bash
57-
winget install GitHub.Copilot
57+
curl -fsSL https://gh.io/copilot-install | bash
58+
```
59+
60+
Or
61+
62+
```bash
63+
wget -qO- https://gh.io/copilot-install | bash
5864
```
5965

66+
Install with [npm](https://www.npmjs.com/package/@github/copilot) (macOS, Linux, and Windows):
67+
68+
```bash
69+
npm install -g @github/copilot
70+
```
71+
72+
Use `| sudo bash` to run as root and install to `/usr/local/bin`.
73+
74+
Set `PREFIX` to install to `$PREFIX/bin/` directory. Defaults to `/usr/local`
75+
when run as root or `$HOME/.local` when run as a non-root user.
76+
6077
### Launching the CLI
6178

6279
```bash

install.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# GitHub Copilot CLI Installation Script
5+
# Usage: curl -fsSL https://gh.io/copilot-install | bash
6+
# or: wget -qO- https://gh.io/copilot-install | bash
7+
# Use | sudo bash to run as root and install to /usr/local/bin
8+
# Export PREFIX to install to $PREFIX/bin/ directory (default: /usr/local for
9+
# root, $HOME/.local for non-root), e.g., export PREFIX=$HOME/custom to install
10+
# to $HOME/custom/bin
11+
12+
echo "Installing GitHub Copilot CLI..."
13+
14+
# Detect platform
15+
case "$(uname -s || echo "")" in
16+
Darwin*) PLATFORM="darwin" ;;
17+
Linux*) PLATFORM="linux" ;;
18+
*)
19+
if command -v winget >/dev/null 2>&1; then
20+
echo "Windows detected. Installing via winget..."
21+
winget install GitHub.Copilot
22+
exit $?
23+
else
24+
echo "Error: Windows detected but winget not found. Please see https://gh.io/install-copilot-readme" >&2
25+
exit 1
26+
fi
27+
;;
28+
esac
29+
30+
# Detect architecture
31+
case "$(uname -m)" in
32+
x86_64|amd64) ARCH="x64" ;;
33+
aarch64|arm64) ARCH="arm64" ;;
34+
*) echo "Error: Unsupported architecture $(uname -m)" >&2 ; exit 1 ;;
35+
esac
36+
37+
DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/latest/download/copilot-${PLATFORM}-${ARCH}.tar.gz"
38+
echo "Downloading from: $DOWNLOAD_URL"
39+
40+
# Download and extract with error handling
41+
TMP_TARBALL="$(mktemp)"
42+
if command -v curl >/dev/null 2>&1; then
43+
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_TARBALL"
44+
elif command -v wget >/dev/null 2>&1; then
45+
wget -qO "$TMP_TARBALL" "$DOWNLOAD_URL"
46+
else
47+
echo "Error: Neither curl nor wget found. Please install one of them."
48+
exit 1
49+
fi
50+
51+
# Check that the file is a valid tarball
52+
if ! tar -tzf "$TMP_TARBALL" >/dev/null 2>&1; then
53+
echo "Error: Downloaded file is not a valid tarball or is corrupted." >&2
54+
rm -f "$TMP_TARBALL"
55+
exit 1
56+
fi
57+
58+
# Check if running as root, fallback to non-root
59+
if [ "$(id -u 2>/dev/null || echo 1)" -eq 0 ]; then
60+
PREFIX="${PREFIX:-/usr/local}"
61+
else
62+
PREFIX="${PREFIX:-$HOME/.local}"
63+
fi
64+
INSTALL_DIR="$PREFIX/bin"
65+
if ! mkdir -p "$INSTALL_DIR"; then
66+
echo "Error: Could not create directory $INSTALL_DIR. You may not have write permissions." >&2
67+
echo "Try running this script with sudo or set PREFIX to a directory you own (e.g., export PREFIX=\$HOME/.local)." >&2
68+
exit 1
69+
fi
70+
71+
# Install binary
72+
if [ -f "$INSTALL_DIR/copilot" ]; then
73+
echo "Notice: Replacing copilot binary found at $INSTALL_DIR/copilot."
74+
fi
75+
tar -xz -C "$INSTALL_DIR" -f "$TMP_TARBALL"
76+
chmod +x "$INSTALL_DIR/copilot"
77+
echo "✓ GitHub Copilot CLI installed to $INSTALL_DIR/copilot"
78+
rm -f "$TMP_TARBALL"
79+
80+
# Check if install directory is in PATH
81+
case ":$PATH:" in
82+
*":$INSTALL_DIR:"*) ;;
83+
*)
84+
echo ""
85+
echo "Warning: $INSTALL_DIR is not in your PATH"
86+
echo "Add it to your PATH by adding this line to your shell profile:"
87+
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
88+
;;
89+
esac
90+
91+
echo ""
92+
echo "Installation complete! Run 'copilot help' to get started."

0 commit comments

Comments
 (0)