2021/12/27

Multiple erlang OTP versions in CentOS7

第一種方式是增加 --libdir

會讓 erlang 24 安裝到 /usr/lib/erlang24/erlang 這個路徑

./configure --prefix=/usr --libdir=/usr/lib/erlang24

另一種方式,還是使用 /usr/lib/erlang,但是在安裝後,將整個目錄複製為獨立的 OTP 目錄,例如安裝了 OTP 24 後,就複製一份為 /usr/lib/erlang24

cp -R /usr/lib/erlang /usr/lib/erlang24

在安裝新的 OTP 前,都先將 /usr/lib/erlang 刪除,安裝後,就可以複製一份該版本的 erlang

otp 20.3

# otp 20 只能使用 wxWidget 3.0
rm -f /usr/local/include/wx
ln -s /usr/local/include/wx-3.0/ /usr/local/include/wx

# 因編譯 wx 會發生錯誤
# 重新安裝 wxWidgets 3.0.3
tar -jxvf wxWidgets-3.0.3.tar.bz2
cd wxWidgets-3.0.3
./configure --with-opengl --enable-debug --enable-unicode --enable-graphics_ctx
make
make install

# 刪除舊的 erlang
rm -rf /usr/lib/erlang

tar zxvf otp_src_20.3.tar.gz
cd otp_src_20.3
./configure --prefix=/usr
make
make install
cd ..

# 備份 otp20.3
cp -R /usr/lib/erlang /usr/lib/erlang20.3

otp 23.3

wxWidget 3.1

## 要先安裝 webkitgtk
# 安裝 nux repo
yum -y install epel-release
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

yum -y install webkitgtk webkitgtk-devel

###
rm -f /usr/local/include/wx

cd wxWidgets-3.1.5
./configure --with-gtk --with-opengl --enable-debug --enable-unicode --enable-compat28 --enable-webview

make
make install
cd ..

ln -s /usr/local/include/wx-3.1/ /usr/local/include/wx
############################
# otp 23 使用 wxWidget 3.1
# 刪除舊的 erlang
rm -rf /usr/lib/erlang

tar zxvf otp_src_23.3.tar.gz
cd otp_src_23.3
./configure --prefix=/usr
make
make install
cd ..

# 備份 otp23.3
cp -R /usr/lib/erlang /usr/lib/erlang23.3

otp 24.0


############################
# otp 24 使用 wxWidget 3.1

# 刪除舊的 erlang
rm -rf /usr/lib/erlang

# SCL 提供安裝多個 gcc 版本的方法
yum -y install centos-release-scl

# 安裝 devtoolset-7
yum -y install devtoolset-7

# 啟動 devtoolset-7
scl enable devtoolset-7 bash

# version check
gcc --version
# gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)


tar zxvf otp_src_24.0.tar.gz
cd otp_src_24.0

./configure --prefix=/usr
make
make install
cd ..

# 備份 otp24.0
cp -R /usr/lib/erlang /usr/lib/erlang24.0

select script

以連結的方式處理不同版本 erlang otp

# otp 20.3
rm -f /usr/lib/erlang
ln -s /usr/lib/erlang20.3 /usr/lib/erlang

# otp 23.3
rm -f /usr/lib/erlang
ln -s /usr/lib/erlang23.3 /usr/lib/erlang

# otp 24.0
rm -f /usr/lib/erlang
ln -s /usr/lib/erlang24.0 /usr/lib/erlang

otp_select.sh

#!/bin/bash

otp20() {
    echo "using erlang 20"
    # otp 20.3
    ln -s /usr/lib/erlang20.3 /usr/lib/erlang
}

otp23() {
    echo "using erlang 23"
    # otp 23.3
    ln -s /usr/lib/erlang23.3 /usr/lib/erlang
}

otp24() {
    echo "using erlang 24"
    # otp 24.0
    ln -s /usr/lib/erlang24.0 /usr/lib/erlang
}

clear() {
    rm -f /usr/lib/erlang
}

status() {
    # https://stackoverflow.com/questions/9560815/how-to-get-erlangs-release-version-number-from-a-shell
    erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell
}

case "$1" in
20)
    clear
    otp20
;;
23)
    clear
    otp23
;;
24)
    clear
    otp24
;;
clear)
    clear
;;
status)
    status
;;
*)
    echo "Usage: $0 {20|23|24|clear|status}"
    esac
    exit 0

沒有留言:

張貼留言