# 安裝


LINE CLI 是單一執行檔，支援 macOS、Linux 與 Windows 的 amd64 和 arm64。下方的安裝程式會自動挑選對應的版本。


## macOS 與 Linux

```sh
curl --proto '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/kongesque/line-cli/main/scripts/install-release.sh | sh
```

安裝程式會挑選對應的發行版、驗證檢查碼、將 `line` 安裝至 `~/.local/bin`，並寫入常見 shell 的 `PATH` 設定。若安裝程式提示需要套用設定，請重新開啟終端機；想在目前的 shell 立刻使用 `line`，可執行 `export PATH="$HOME/.local/bin:$PATH"`。

macOS 也可以改用 Homebrew：

```sh
brew install kongesque/tap/line-cli
```


## Windows

在 PowerShell 執行：

```powershell
irm https://raw.githubusercontent.com/kongesque/line-cli/main/scripts/install-release.ps1 | iex
```

安裝程式會將 `line.exe` 安裝到 `%LOCALAPPDATA%\line-cli\bin`，並將該資料夾加入使用者的 `PATH`。必要時請重新開啟 PowerShell。

若 Windows 顯示「應用程式控制原則已封鎖此檔案」，表示「智慧型應用程式控制」拒絕了未簽署的 `line.exe`。請關閉此功能（關閉後在這套 Windows 上無法再開啟），或[從原始碼建置](https://kongesque.github.io/line-cli/zh-tw/reference/build/)。


## 確認安裝結果

```sh
line version
line help
```

發行版執行檔目前尚未經過數位簽署與公證。你可以到
[GitHub Releases](https://github.com/kongesque/line-cli/releases/latest) 查看。


## Linux 桌面金鑰圈

在 Linux 桌面環境中，CLI 會將儲存金鑰保存在桌面金鑰圈。Debian 或 Ubuntu 請安裝：

```sh
sudo apt install libsecret-tools gnome-keyring
```

金鑰圈必須已啟動、解鎖，且與 `line` 位於同一個 D-Bus 工作階段。沒有桌面金鑰圈的伺服器與
SSH 主機請使用 `line login --headless`；詳見 [Linux 伺服器](https://kongesque.github.io/line-cli/zh-tw/guides/linux-servers/)。


## 安裝到其他資料夾

兩種安裝程式都會讀取 `LINE_CLI_INSTALL_DIR`：

```sh
curl --proto '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/kongesque/line-cli/main/scripts/install-release.sh | LINE_CLI_INSTALL_DIR="$HOME/bin" sh
```

```powershell
$env:LINE_CLI_INSTALL_DIR = "$HOME\Tools\line"
irm https://raw.githubusercontent.com/kongesque/line-cli/main/scripts/install-release.ps1 | iex
```

指定資料夾時，macOS 與 Linux 的安裝程式不會修改 shell 設定檔；若該資料夾還不在 `PATH` 中，會印出 `export PATH` 這一行，讓你自行加入。Windows 安裝程式則照常把資料夾加入使用者的 `PATH`。之後 `line update` 也會繼續使用你選的資料夾。


## 自行下載發行版

每個[發行版](https://github.com/kongesque/line-cli/releases/latest)都依系統提供一個封存檔 `line-OS-ARCH.tar.gz`（OS 為 `darwin`、`linux` 或 `windows`，ARCH 為 `amd64` 或 `arm64`），另附 `SHA256SUMS.txt`。以 Linux 為例：

```sh
curl -fLO https://github.com/kongesque/line-cli/releases/latest/download/line-linux-amd64.tar.gz
curl -fLO https://github.com/kongesque/line-cli/releases/latest/download/SHA256SUMS.txt
grep ' line-linux-amd64.tar.gz$' SHA256SUMS.txt | sha256sum -c   # macOS: shasum -a 256 -c
tar -xzf line-linux-amd64.tar.gz
```

接著將 `line` 移到 `PATH` 內的資料夾。在 Windows 上，請將 `Get-FileHash line-windows-amd64.tar.gz` 的結果與 `SHA256SUMS.txt` 中對應的那一行比對，再用 `tar -xzf` 解出 `line.exe`。若 macOS 封鎖了用瀏覽器下載的檔案，請改用上面的 `curl` 下載，或使用安裝程式或 Homebrew。

以這種方式安裝的執行檔沒有 `.line-cli-install` 安裝紀錄，因此 `line update` 只會顯示發行版頁面，不會替換檔案。若想使用自動更新，請改用安裝程式安裝。


## 解除安裝

請趁 `line` 還在時先登出。這會撤銷此裝置的工作階段，並刪除已儲存的憑證：

```sh
line logout
```

接著依安裝方式移除執行檔：

| 安裝方式 | 移除指令 |
| --- | --- |
| Homebrew | `brew uninstall line-cli` |
| macOS 或 Linux 安裝程式 | `rm ~/.local/bin/line ~/.local/bin/.line-cli-install` |
| Windows 安裝程式 | `Remove-Item -Recurse "$env:LOCALAPPDATA\line-cli"` |

在 Windows 上，也請將 `%LOCALAPPDATA%\line-cli\bin` 從使用者的 `PATH` 移除（搜尋「編輯您帳戶的環境變數」）。在 macOS 與 Linux 上，安裝程式可能已在 shell 設定檔的 `# Added by the LINE CLI installer` 下方加入一行 `export PATH`；若沒有其他程式使用 `~/.local/bin`，請刪除這兩行。

登出後仍會留下一個存放鎖定檔的小型 `line-cli` 資料夾：Linux 為 `~/.config/line-cli`，macOS 為 `~/Library/Caches/line-cli`。不再使用 LINE CLI 後即可刪除。


---
Source: https://kongesque.github.io/line-cli/zh-tw/start/install/
