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?

より安全かつ正確に ahcd-go を削除

Posted at

前書き

Python の標準ライブラリ に含まれている(xml.etree.ElementTree, csv, os) を使ってスプリクトを書いた方が簡単で、その後のデータの加工など使い勝手がいいので、綺麗にahcd-go並びに関連を削除したいと思いました。

環境

iMac Retina 5k, 27-inch, 2017
macOS Ventura 13.7.4
MacBook Air (15インチ, M2, 2023)
MacOS:Sonoma14.5

1. ahcd-go の削除

yourname@yournamenoiMac ~ % if [ -n "$(go env GOPATH)" ] && [ -d "$(go env GOPATH)/bin" ]; then
    rm -f "$(go env GOPATH)/bin/ahcd-go"
fi
何も表示されなければ削除成功
yourname@yournamenoiMac ~ %command -v ahcd-go
GOPATH が空ならインストール場所を調査(空の時の誤削除を防止)

command -v ahcd-go の結果を見て個別に削除

yourname@yournamenoiMac ~ % if [ -z "$(go env GOPATH)" ]; then
    echo "GOPATH is empty. Checking installed location..."
    if command -v ahcd-go &>/dev/null; then
        echo "ahcd-go found at $(command -v ahcd-go). Deleting..."
        sudo rm -f "$(command -v ahcd-go)"
    else
        echo "ahcd-go is not installed."
    fi
fi

2. ahcd-go のキャッシュや依存ファイルを削除

yourname@yournamenoiMac ~ % if [ -n "$(go env GOPATH)" ]; then
    rm -rf "$(go env GOPATH)/pkg/mod/github.com/your_repo/ahcd-go"
fi

3. Go を削除(不要なら)

yourname@yournamenoiMac ~ % if command -v brew &>/dev/null; then
    brew uninstall go
else
    sudo rm -rf /usr/local/go
    if [ -n "$(go env GOPATH)" ]; then
        rm -rf "$(go env GOPATH)"
    fi
fi

4. 環境変数を削除

sed の -i オプションで macOS / Linux 両対応

yourname@yournamenoiMac ~ % if command -v sed &>/dev/null; then
    if [[ "$OSTYPE" == "darwin"* ]]; then
        sed -i '' '/export PATH=.*go/d' ~/.zshrc ~/.bash_profile ~/.profile
        sed -i '' '/export GOPATH=/d' ~/.zshrc ~/.bash_profile ~/.profile
    else  # Linux (GNU sed)
        sed -i '/export PATH=.*go/d' ~/.zshrc ~/.bash_profile ~/.profile
        sed -i '/export GOPATH=/d' ~/.zshrc ~/.bash_profile ~/.profile
    fi
fi

5. 設定を反映

yourname@yournamenoiMac ~ % [ -f ~/.zshrc ] && source ~/.zshrc
yourname@yournamenoiMac ~ % [ -f ~/.bash_profile ] && source ~/.bash_profile
yourname@yournamenoiMac ~ % [ -f ~/.profile ] && source ~/.profile
yourname@yournamenoiMac ~ % command -v go
何も表示されなければ削除成功
yourname@yournamenoiMac ~ % 
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?