Last active
April 28, 2021 12:30
-
-
Save kourbou/3a6e5a5716b8ace1ed1d203d77cddba8 to your computer and use it in GitHub Desktop.
Install (or Update) Ninja Build on Windows (run in admin Powershell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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