Skip to content

Add elixir-lang.org/install.sh and install.bat #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _data/elixir-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ stable: v1_17
v1_17:
name: v1.17
minimum_otp: 25.0
recommended_otp: 27.1.2
otp_versions: [27, 26, 25]
version: 1.17.3

Expand Down
164 changes: 164 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
@echo off
REM See latest version at:
REM https://github.com/elixir-lang/elixir-lang.github.com/blob/main/install.bat

setlocal EnableDelayedExpansion

set "otp_version=latest"
set "elixir_version=latest"
set "force=false"

goto :main

:usage
echo Usage: install.bat [arguments] [options]
echo.
echo Arguments:
echo.
echo elixir@VERSION Install specific Elixir version. The version can be X.Y.Z, latest, or main
echo otp@VERSION Install specific Erlang/OTP version. The version can be X.Y.Z or latest
echo.
echo By default, elixir@latest and otp@latest are installed.
echo.
echo Options:
echo.
echo -f, --force Forces installation even if it was previously installed
echo -h, --help Prints this help
echo.
echo Examples:
echo.
echo install.bat
echo install.bat [email protected] [email protected]
echo install.bat elixir@main
echo.
goto :eof

:main
for %%i in (%*) do (
set arg=%%i

if "!arg:~0,7!" == "elixir@" (
set "elixir_version=!arg:~7!"
) else if "!arg:~0,4!" == "otp@" (
set "otp_version=!arg:~4!"
) else if "!arg!" == "-f" (
set "force=true"
) else if "!arg!" == "--force" (
set "force=true"
) else if "!arg!" == "-h" (
call :usage
exit /b 0
) else if "!arg!" == "--help" (
call :usage
exit /b 0
) else (
echo error: unknown argument !arg!
exit /b 1
)
)

if "!otp_version!" == "latest" (
set "url=https://github.com/erlef/otp_builds/releases/latest"
for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a
set "otp_version=!url:*releases/tag/OTP-=!"
)

if "!elixir_version!" == "latest" (
set "url=https://github.com/elixir-lang/elixir/releases/latest"
for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a
set "elixir_version=!url:*releases/tag/v=!"
)

for /f "tokens=1 delims=." %%A in ("!otp_version!") do set "elixir_otp_release=%%A"
for /f "tokens=1,2 delims=." %%A in ("!elixir_version!") do set "elixir_major_minor=%%A.%%B"
if "%elixir_major_minor%" == "1.15" (
if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26"
) else if "%elixir_major_minor%" == "1.16" (
if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26"
) else if "%elixir_major_minor%" == "1.14" (
if %elixir_otp_release% GEQ 25 set "elixir_otp_release=25"
)

set "root_dir=%USERPROFILE%\.elixir-install"
set "tmp_dir=%root_dir%\tmp"
mkdir %tmp_dir% 2>nul
set "otp_dir=%root_dir%\installs\otp\%otp_version%"
set "elixir_dir=%root_dir%\installs\elixir\%elixir_version%-otp-%elixir_otp_release%"

call :install_otp
if %errorlevel% neq 0 exit /b 1

set /p="checking OTP... "<nul
set "PATH=%otp_dir%\bin;%PATH%"
"%otp_dir%\bin\erl.exe" -noshell -eval "io:put_chars(erlang:system_info(otp_release) ++ "" ok\n""), halt()."

call :install_elixir
if %errorlevel% neq 0 exit /b 1

set /p="checking Elixir... "<nul
call "%elixir_dir%\bin\elixir.bat" -e "IO.write(System.version())"
echo. ok

echo.
echo If you are using powershell, run this (or add to your $PROFILE):
echo.
echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\otp\!otp_version!\bin;$env:PATH"
echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;$env:PATH"
echo.
echo If you are using cmd, run this:
echo.
echo set PATH=%%USERPROFILE%%\.elixir-install\installs\otp\!otp_version!\bin;%%PATH%%
echo set PATH=%%USERPROFILE%%\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;%%PATH%%
echo.
goto :eof

:install_otp
set "otp_zip=otp_win64_%otp_version%.zip"

if "%force%" == "true" (
if exist "%otp_dir%" (
rmdir /s /q "%otp_dir%"
)
)

if not exist "%otp_dir%\bin" (
if exist "%otp_dir%" (
rmdir /s /q "%otp_dir%"
)

set otp_url=https://github.com/erlang/otp/releases/download/OTP-!otp_version!/%otp_zip%
echo downloading !otp_url!...
curl.exe -fsSLo %tmp_dir%\%otp_zip% "!otp_url!" || exit /b 1

echo unpacking %tmp_dir%\%otp_zip%
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%otp_zip% -DestinationPath %otp_dir%"
del /f /q "%tmp_dir%\%otp_zip%"
cd /d "%otp_dir%"

if not exist "c:\windows\system32\vcruntime140.dll" (
echo Installing VC++ Redistributable...
.\vc_redist.exe /quiet /norestart
)
)
exit /b 0
goto :eof

:install_elixir
set "elixir_zip=elixir-!elixir_version!-otp-!elixir_otp_release!.zip"

if "%force%" == "true" (
if exist "%elixir_dir%" (
rmdir /s /q "%elixir_dir%"
)
)

if not exist "%elixir_dir%\bin" (
set "elixir_url=https://github.com/elixir-lang/elixir/releases/download/v!elixir_version!/elixir-otp-%elixir_otp_release%.zip"
echo downloading !elixir_url!...
curl.exe -fsSLo "%tmp_dir%\%elixir_zip%" "!elixir_url!" || exit /b 1

echo unpacking %tmp_dir%\%elixir_zip%
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%elixir_zip% -DestinationPath %elixir_dir%"
del /f /q %tmp_dir%\%elixir_zip%
)
goto :eof
32 changes: 31 additions & 1 deletion install.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,42 @@ image: /images/social/elixir-og-card.jpg

{% include toc.html %}

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.
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.

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.

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

## Install Script

Elixir and Erlang/OTP can be quickly installed for macOS, Windows, or Ubuntu using an `install.sh`/`install.bat` script:

If you are using bash (macOS/Ubuntu/Windows), run:

```sh
curl -fsSO {{ site.url }}/install.sh
sh install.sh elixir@{{ stable.version }} otp@{{ stable.recommended_otp }}
installs_dir=$HOME/.elixir-install/installs
export PATH=$installs_dir/otp/{{ stable.recommended_otp }}/bin:$PATH
export PATH=$installs_dir/elixir/{{ stable.version }}-otp-{{ stable.otp_versions[0] }}/bin:$PATH
iex
```

If you are using PowerShell (Windows), run:

```pwsh
curl.exe -fsSO {{ site.url }}/install.bat
.\install.bat elixir@{{ stable.version }} otp@{{ stable.recommended_otp }}
$installs_dir = "$env:USERPROFILE\.elixir-install\installs"
$env:PATH = "$installs_dir\otp\{{ stable.recommended_otp }}\bin;$env:PATH"
$env:PATH = "$installs_dir\elixir\{{ stable.version }}-otp-{{ stable.otp_versions[0] }}\bin;$env:PATH"
iex.bat
```

Use `install.sh --help` or `install.bat --help` to learn more about available arguments and options.

Install scripts support installing Elixir 1.14+.

## By Operating System

Install Elixir according to your operating system and tool of choice.
Expand Down
Loading