Skip to content

Commit 5ef6c8a

Browse files
authored
Add elixir-lang.org/install.sh and install.bat (#1778)
1 parent 3f7f291 commit 5ef6c8a

File tree

4 files changed

+458
-1
lines changed

4 files changed

+458
-1
lines changed

_data/elixir-versions.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ stable: v1_17
33
v1_17:
44
name: v1.17
55
minimum_otp: 25.0
6+
recommended_otp: 27.1.2
67
otp_versions: [27, 26, 25]
78
version: 1.17.3
89

install.bat

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
@echo off
2+
REM See latest version at:
3+
REM https://github.com/elixir-lang/elixir-lang.github.com/blob/main/install.bat
4+
5+
setlocal EnableDelayedExpansion
6+
7+
set "otp_version=latest"
8+
set "elixir_version=latest"
9+
set "force=false"
10+
11+
goto :main
12+
13+
:usage
14+
echo Usage: install.bat [arguments] [options]
15+
echo.
16+
echo Arguments:
17+
echo.
18+
echo elixir@VERSION Install specific Elixir version. The version can be X.Y.Z, latest, or main
19+
echo otp@VERSION Install specific Erlang/OTP version. The version can be X.Y.Z or latest
20+
echo.
21+
echo By default, elixir@latest and otp@latest are installed.
22+
echo.
23+
echo Options:
24+
echo.
25+
echo -f, --force Forces installation even if it was previously installed
26+
echo -h, --help Prints this help
27+
echo.
28+
echo Examples:
29+
echo.
30+
echo install.bat
31+
32+
echo install.bat elixir@main
33+
echo.
34+
goto :eof
35+
36+
:main
37+
for %%i in (%*) do (
38+
set arg=%%i
39+
40+
if "!arg:~0,7!" == "elixir@" (
41+
set "elixir_version=!arg:~7!"
42+
) else if "!arg:~0,4!" == "otp@" (
43+
set "otp_version=!arg:~4!"
44+
) else if "!arg!" == "-f" (
45+
set "force=true"
46+
) else if "!arg!" == "--force" (
47+
set "force=true"
48+
) else if "!arg!" == "-h" (
49+
call :usage
50+
exit /b 0
51+
) else if "!arg!" == "--help" (
52+
call :usage
53+
exit /b 0
54+
) else (
55+
echo error: unknown argument !arg!
56+
exit /b 1
57+
)
58+
)
59+
60+
if "!otp_version!" == "latest" (
61+
set "url=https://github.com/erlef/otp_builds/releases/latest"
62+
for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a
63+
set "otp_version=!url:*releases/tag/OTP-=!"
64+
)
65+
66+
if "!elixir_version!" == "latest" (
67+
set "url=https://github.com/elixir-lang/elixir/releases/latest"
68+
for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a
69+
set "elixir_version=!url:*releases/tag/v=!"
70+
)
71+
72+
for /f "tokens=1 delims=." %%A in ("!otp_version!") do set "elixir_otp_release=%%A"
73+
for /f "tokens=1,2 delims=." %%A in ("!elixir_version!") do set "elixir_major_minor=%%A.%%B"
74+
if "%elixir_major_minor%" == "1.15" (
75+
if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26"
76+
) else if "%elixir_major_minor%" == "1.16" (
77+
if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26"
78+
) else if "%elixir_major_minor%" == "1.14" (
79+
if %elixir_otp_release% GEQ 25 set "elixir_otp_release=25"
80+
)
81+
82+
set "root_dir=%USERPROFILE%\.elixir-install"
83+
set "tmp_dir=%root_dir%\tmp"
84+
mkdir %tmp_dir% 2>nul
85+
set "otp_dir=%root_dir%\installs\otp\%otp_version%"
86+
set "elixir_dir=%root_dir%\installs\elixir\%elixir_version%-otp-%elixir_otp_release%"
87+
88+
call :install_otp
89+
if %errorlevel% neq 0 exit /b 1
90+
91+
set /p="checking OTP... "<nul
92+
set "PATH=%otp_dir%\bin;%PATH%"
93+
"%otp_dir%\bin\erl.exe" -noshell -eval "io:put_chars(erlang:system_info(otp_release) ++ "" ok\n""), halt()."
94+
95+
call :install_elixir
96+
if %errorlevel% neq 0 exit /b 1
97+
98+
set /p="checking Elixir... "<nul
99+
call "%elixir_dir%\bin\elixir.bat" -e "IO.write(System.version())"
100+
echo. ok
101+
102+
echo.
103+
echo If you are using powershell, run this (or add to your $PROFILE):
104+
echo.
105+
echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\otp\!otp_version!\bin;$env:PATH"
106+
echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;$env:PATH"
107+
echo.
108+
echo If you are using cmd, run this:
109+
echo.
110+
echo set PATH=%%USERPROFILE%%\.elixir-install\installs\otp\!otp_version!\bin;%%PATH%%
111+
echo set PATH=%%USERPROFILE%%\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;%%PATH%%
112+
echo.
113+
goto :eof
114+
115+
:install_otp
116+
set "otp_zip=otp_win64_%otp_version%.zip"
117+
118+
if "%force%" == "true" (
119+
if exist "%otp_dir%" (
120+
rmdir /s /q "%otp_dir%"
121+
)
122+
)
123+
124+
if not exist "%otp_dir%\bin" (
125+
if exist "%otp_dir%" (
126+
rmdir /s /q "%otp_dir%"
127+
)
128+
129+
set otp_url=https://github.com/erlang/otp/releases/download/OTP-!otp_version!/%otp_zip%
130+
echo downloading !otp_url!...
131+
curl.exe -fsSLo %tmp_dir%\%otp_zip% "!otp_url!" || exit /b 1
132+
133+
echo unpacking %tmp_dir%\%otp_zip%
134+
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%otp_zip% -DestinationPath %otp_dir%"
135+
del /f /q "%tmp_dir%\%otp_zip%"
136+
cd /d "%otp_dir%"
137+
138+
if not exist "c:\windows\system32\vcruntime140.dll" (
139+
echo Installing VC++ Redistributable...
140+
.\vc_redist.exe /quiet /norestart
141+
)
142+
)
143+
exit /b 0
144+
goto :eof
145+
146+
:install_elixir
147+
set "elixir_zip=elixir-!elixir_version!-otp-!elixir_otp_release!.zip"
148+
149+
if "%force%" == "true" (
150+
if exist "%elixir_dir%" (
151+
rmdir /s /q "%elixir_dir%"
152+
)
153+
)
154+
155+
if not exist "%elixir_dir%\bin" (
156+
set "elixir_url=https://github.com/elixir-lang/elixir/releases/download/v!elixir_version!/elixir-otp-%elixir_otp_release%.zip"
157+
echo downloading !elixir_url!...
158+
curl.exe -fsSLo "%tmp_dir%\%elixir_zip%" "!elixir_url!" || exit /b 1
159+
160+
echo unpacking %tmp_dir%\%elixir_zip%
161+
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%elixir_zip% -DestinationPath %elixir_dir%"
162+
del /f /q %tmp_dir%\%elixir_zip%
163+
)
164+
goto :eof

install.markdown

+31-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,42 @@ image: /images/social/elixir-og-card.jpg
1010

1111
{% include toc.html %}
1212

13-
The quickest way to install Elixir is through a distribution or using one of the available installers. If such an option is not available, then we recommend using the precompiled packages or compiling the language yourself. All of these options are detailed next.
13+
The quickest way to install Elixir is through install scripts, operating system package manager, or using one of the available installers. If such an option is not available, then we recommend using the precompiled packages or compiling the language yourself. All of these options are detailed next.
1414

1515
Note that Elixir {{ stable.name }} requires Erlang {{ stable.minimum_otp }} or later. Many of the instructions below will automatically install Erlang for you. If they do not, the "Installing Erlang" section has you covered.
1616

1717
If you are not sure if you have Elixir installed or not, you can run `elixir --version` in your terminal.
1818

19+
## Install Script
20+
21+
Elixir and Erlang/OTP can be quickly installed for macOS, Windows, or Ubuntu using an `install.sh`/`install.bat` script:
22+
23+
If you are using bash (macOS/Ubuntu/Windows), run:
24+
25+
```sh
26+
curl -fsSO {{ site.url }}/install.sh
27+
sh install.sh elixir@{{ stable.version }} otp@{{ stable.recommended_otp }}
28+
installs_dir=$HOME/.elixir-install/installs
29+
export PATH=$installs_dir/otp/{{ stable.recommended_otp }}/bin:$PATH
30+
export PATH=$installs_dir/elixir/{{ stable.version }}-otp-{{ stable.otp_versions[0] }}/bin:$PATH
31+
iex
32+
```
33+
34+
If you are using PowerShell (Windows), run:
35+
36+
```pwsh
37+
curl.exe -fsSO {{ site.url }}/install.bat
38+
.\install.bat elixir@{{ stable.version }} otp@{{ stable.recommended_otp }}
39+
$installs_dir = "$env:USERPROFILE\.elixir-install\installs"
40+
$env:PATH = "$installs_dir\otp\{{ stable.recommended_otp }}\bin;$env:PATH"
41+
$env:PATH = "$installs_dir\elixir\{{ stable.version }}-otp-{{ stable.otp_versions[0] }}\bin;$env:PATH"
42+
iex.bat
43+
```
44+
45+
Use `install.sh --help` or `install.bat --help` to learn more about available arguments and options.
46+
47+
Install scripts support installing Elixir 1.14+.
48+
1949
## By Operating System
2050

2151
Install Elixir according to your operating system and tool of choice.

0 commit comments

Comments
 (0)