-
Notifications
You must be signed in to change notification settings - Fork 3
/
ruby_install.ps1
92 lines (79 loc) · 3.21 KB
/
ruby_install.ps1
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
$rubies = @(
@{
"version" = "Ruby 2.6.9-1"
"install_path" = "C:\Ruby26"
"download_url" = "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.9-1/rubyinstaller-2.6.9-1-x86.exe"
"devkit_url" = ""
"devkit_paths" = @()
"bundlerV2" = $true
}
@{
"version" = "Ruby 2.6.9-1 (x64)"
"install_path" = "C:\Ruby26-x64"
"download_url" = "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.9-1/rubyinstaller-2.6.9-1-x64.exe"
"devkit_url" = ""
"devkit_paths" = @()
"bundlerV2" = $true
}
@{
"version" = "Ruby 2.7.8-1"
"install_path" = "C:\Ruby27"
"download_url" = "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.7.8-1/rubyinstaller-2.7.8-1-x86.exe"
"devkit_url" = ""
"devkit_paths" = @()
"bundlerV2" = $true
}
@{
"version" = "Ruby 2.7.8-1 (x64)"
"install_path" = "C:\Ruby27-x64"
"download_url" = "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.7.8-1/rubyinstaller-2.7.8-1-x64.exe"
"devkit_url" = ""
"devkit_paths" = @()
"bundlerV2" = $true
}
)
function UpdateRubyPath($rubyPath) {
$env:path = ($env:path -split ';' | Where-Object { -not $_.contains('\Ruby') }) -join ';'
$env:path = "$rubyPath;$env:path"
}
function Install-Ruby($ruby) {
Write-Host "Installing $($ruby.version)" -ForegroundColor Cyan
# uninstall existing
$rubyUninstallPath = "$ruby.install_path\unins000.exe"
if ([IO.File]::Exists($rubyUninstallPath)) {
Write-Host " Uninstalling previous Ruby 2.4..." -ForegroundColor Gray
"`"$rubyUninstallPath`" /silent" | out-file "$env:temp\uninstall-ruby.cmd" -Encoding ASCII
& "$env:temp\uninstall-ruby.cmd"
del "$env:temp\uninstall-ruby.cmd"
Start-Sleep -s 5
}
if (Test-Path $ruby.install_path) {
Write-Host " Deleting $($ruby.install_path)" -ForegroundColor Gray
Remove-Item $ruby.install_path -Force -Recurse
}
$exePath = "$($env:TEMP)\rubyinstaller.exe"
Write-Host " Downloading $($ruby.version) from $($ruby.download_url)" -ForegroundColor Gray
(New-Object Net.WebClient).DownloadFile($ruby.download_url, $exePath)
Write-Host "Installing..." -ForegroundColor Gray
cmd /c start /wait $exePath /verysilent /allusers /dir="$($ruby.install_path.replace('\', '/'))" /tasks="noassocfiles,nomodpath,noridkinstall"
del $exePath
Write-Host "Installed" -ForegroundColor Green
# setup Ruby
UpdateRubyPath "$($ruby.install_path)\bin"
Write-Host "ruby --version" -ForegroundColor Gray
cmd /c ruby --version
Write-Host "gem --version" -ForegroundColor Gray
cmd /c gem --version
# list installed gems
Write-Host "gem list --local" -ForegroundColor Gray
cmd /c gem list --local
# delete temp path
if ($tempPath) {
Write-Host " Cleaning up..." -ForegroundColor Gray
Remove-Item $tempPath -Force -Recurse
}
Write-Host " Done!" -ForegroundColor Green
}
for ($i = 0; $i -lt $rubies.Count; $i++) {
Install-Ruby $rubies[$i]
}