2
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?

Elixirのバージョンを上げるのを自動化してみた

Last updated at Posted at 2024-02-15

asdfをインストールするスクリプト

#!/bin/bash

# If you use Linux, git clone asdf.
# After install asdf, add path in current shell
# and add plugin elixir and erlang.
_linux_install_asdf() {
  echo "----- Linux install asdf."
  git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0

  echo "----- Add path to ~/.bashrc."

  # .bashrc
  echo '# asdf' >> ~/.bashrc
  echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
  echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc

  source ~/.bashrc
  which asdf

  echo "----- Add plugin Elixir."
  asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git

  echo "----- Add plugin Erlang."
  asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git

  echo "----- Install dependencies erlang."
  sudo apt install -y libssl-dev automake autoconf libncurses5-dev
}

# If you use macOS, execute `brew install asdf`.
# After install asdf, add path in current shell
# and add plugin elixir and erlang.
_macOS_install_asdf() {
  echo "----- macOS install asdf."
  brew update
  brew install asdf

  echo "----- Add path to ~/.zshrc."

  # .zshrc
  echo '# asdf' >> ${ZDOTDIR:-~}/.zshrc
  echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

  source ${ZDOTDIR:-~}/.zshrc
  which asdf

  echo "----- Add plugin Elixir."
  asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git

  echo "----- Add plugin Erlang."
  asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
}

install_asdf() {
  if [ "$(uname)" = 'Darwin' ]; then
    _macOS_install_asdf
  else
    _linux_install_asdf
  fi
}

# Execute this script current shell. For example,
# $ source install_asdf.sh
install_asdf

Elixirをインストール/バージョンアップデートするスクリプト

#!/bin/bash

# Install version
ELIXIR_V=1.16.2
ERLANG_V=26.2.2

# Update asdf.
# If you use macOS, execute `brew upgrade asdf`.
# If you use Linux, execute `asdf update`.
_update_asdf() {
  if [ "$(uname)" = 'Darwin' ]; then
    echo "----- macOS update brew asdf."
    brew update
    brew upgrade asdf
  else
    echo "----- Linux update asdf."
    asdf update
  fi
}

# List installable elixir and eralng versions.
version_list() {
  _update_asdf
  paste <(echo "Elixir" && asdf list-all elixir | tail -n 15) \
        <(echo "Erlang" && asdf list-all erlang | tail -n 15) \
  | awk '{printf "%-20s %s\n",$1,$2}'
}

# Uninstall elixir and erlang current setting versions.
uninstall() {
  echo "----- Uninstal Elixir."
  asdf uninstall elixir

  echo "----- Uninstall Erlang."
  asdf uninstall erlang $(asdf list erlang | perl -pe 's/\*//g')

  asdf list
}

# Install specified elixir and erlang version.
# And set global installed version.
install_elixir() {
  _update_asdf

  echo "----- Install Elixir."
  asdf install elixir ${ELIXIR_V}

  echo "----- Install Erlang."
  asdf install erlang ${ERLANG_V}

  # echo "----- Set local installed version."
  # asdf local elixir ${ELIXIR_V}
  # asdf local erlang ${ERLANG_V}

  echo "----- Set global installed version."
  asdf global elixir ${ELIXIR_V}
  asdf global erlang ${ERLANG_V}

  asdf current
}

version_list
install_elixir
2
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
2
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?