-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathubuntu-pyenv-installer.sh
executable file
·155 lines (130 loc) · 3.32 KB
/
ubuntu-pyenv-installer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
colorize() {
if [ -t 1 ]; then
printf "\e[%sm%s\e[m\n\n" "$1" "$2"
else
echo -n "$2"
fi
}
echo
colorize 33 "Ubuntu Pyenv Installer"
current_version=`python3 -V | grep -Eo '([0-9]{1,3}[\.]){2}[0-9]{1,3}'`
echo " The current Python version is: ${current_version} (system)"
python_version=`curl --silent https://www.python.org/doc/versions/ \
| grep -oP 'Python \d+\.\d+\.\d+' \
| head -1`
echo " The latest Python version is: ${python_version}"
echo
colorize 33 "What should I do?"
echo " 1. Install Pyenv only"
echo " 2. Install Pyenv, and the latest Python version ($python_version)"
echo " 3. Install Pyenv, the latest Python ($python_version), and set it as the global version"
echo
read -p "Make your choice (1, 2 or 3): " answer
echo
apt_update(){
colorize 92 "Updating system packages lists"
sudo apt update
echo
}
create_symlink_to_python3(){
sudo ln -s /usr/bin/python3 /usr/bin/python
}
install_python_dependencies() {
colorize 92 "Installing Python build dependencies"
sudo apt install -y \
make \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev
echo
}
install_git(){
colorize 92 "Installing Git"
sudo apt install -y git
echo
}
install_pyenv(){
colorize 92 'Installing Pyenv'
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo
colorize 92 'Writing Pyenv config to ./bashrc file'
sed -Ei -e '/^([^#]|$)/ {a \
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
eval "$(pyenv init --path)"
a \
eval "$(pyenv virtualenv-init -)"
a \
\n
' -e ':a' -e '$!{n;ba};}' ~/.bashrc
echo
colorize 92 "Reloading ./bashrc"
source ~/.bashrc
echo
}
install_python(){
colorize 92 "Installing Python $python_version"
pyenv install $python_version
}
set_python_global(){
colorize 92 "Setting Python $python_version as global version"
pyenv global $python_version
}
restart_current_shell(){
exec $SHELL
}
done_message(){
echo
colorize 93 "At the beginning of the ${HOME}/.bashrc file were added these lines:"
echo ' export PYENV_ROOT="$HOME/.pyenv"'
echo ' export PATH="$PYENV_ROOT/bin:$PATH"'
echo ' eval "$(pyenv init --path)"'
echo ' eval "$(pyenv virtualenv-init -)"'
echo
echo "To uninstall Pyenv just delete them from ${HOME}/.bashrc file, and"
echo "then delete ${PYENV_ROOT} directory"
echo
echo 'Done!'
}
install_minimum(){
apt_update
install_python_dependencies
install_git
install_pyenv
create_symlink_to_python3
}
if [[ $answer == '1' ]]; then
install_minimum
done_message
restart_current_shell
elif [[ $answer == '2' ]]; then
install_minimum
install_python
done_message
restart_current_shell
elif [[ $answer == '3' ]]; then
install_minimum
install_python
set_python_global
done_message
restart_current_shell
else
echo "Invalid input. Try again"
exit 0
fi