Skip to content

Instantly share code, notes, and snippets.

@kourbou
Last active April 28, 2021 12:30
Show Gist options
  • Select an option

  • Save kourbou/3a6e5a5716b8ace1ed1d203d77cddba8 to your computer and use it in GitHub Desktop.

Select an option

Save kourbou/3a6e5a5716b8ace1ed1d203d77cddba8 to your computer and use it in GitHub Desktop.
Install (or Update) Ninja Build on Windows (run in admin Powershell)
$repo = "ninja-build/ninja"
$file = "ninja-win.zip"
$dest = "C:\Program Files\Ninja"
$releases = "https://api.github.com/repos/$repo/releases/latest"
$asset = Invoke-RestMethod -Uri $releases |
Select-Object -ExpandProperty assets |
Where-Object {$_.name -eq $file}
$tmp = New-TemporaryFile | Rename-Item -NewName { $_ -replace 'tmp$', 'zip' } -PassThru
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $tmp
New-Item -ItemType Directory -Force -Path $dest | Out-Null
$tmp | Expand-Archive -DestinationPath $dest -Force
$tmp | Remove-Item
# Add destination folder to Machine PATH
$target = [EnvironmentVariableTarget]::Machine
$paths = [Environment]::GetEnvironmentVariable('Path', $target) -split ';'
if ($paths -notcontains $dest) {
$paths = $paths + $dest | where { $_ }
[Environment]::SetEnvironmentVariable('Path', $paths -join ';', $target)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment