MegaBites-AI/Windows-powershell
0372
1# Build PowerShell on Linux2 3This guide will walk you through building PowerShell on Linux.4We'll start by showing how to set up your environment from scratch.5 6## Environment7 8These instructions are written assuming Ubuntu 24.04 LTS (the CI uses ubuntu-latest).9The build module works on a best-effort basis for other distributions.10 11### Git Setup12 13Using Git requires it to be set up correctly;14refer to the [Working with the PowerShell Repository](../git/README.md),15[Readme](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md).16 17**This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it.**18 19### Toolchain Setup20 21We use the [.NET Command-Line Interface][dotnet-cli] (`dotnet`) to build the managed components.22 23Installing the toolchain is as easy as running `Start-PSBootstrap` in PowerShell.24Of course, this requires a self-hosted copy of PowerShell on Linux.25 26Fortunately, this is as easy as [downloading and installing the package](https://learn.microsoft.com/en-us/powershell/scripting/install/install-other-linux#binary-archives).27The `./tools/install-powershell.sh` script will also install the PowerShell package.28 29In Bash:30 31```sh32./tools/install-powershell.sh33 34pwsh35```36 37You should now be in a PowerShell console host that is installed.38Just import our module, bootstrap the dependencies, and build!39 40In PowerShell:41 42```powershell43Import-Module ./build.psm144Start-PSBootstrap -Scenario Both45```46 47The `Start-PSBootstrap` function does the following:48 49- Installs build dependencies and packaging tools via `apt-get` (or equivalent package manager)50- Downloads and installs the .NET SDK (currently version 10.0.100-rc.1) to `~/.dotnet`51 52If you want to use `dotnet` outside of `Start-PSBuild`, add `~/.dotnet` to your `PATH` environment variable.53 54[dotnet-cli]: https://learn.microsoft.com/dotnet/core/tools/55 56## Build using our module57 58We maintain a [PowerShell module](../../build.psm1) with the function `Start-PSBuild` to build PowerShell.59Since this is PowerShell code, it requires self-hosting.60If you have followed the toolchain setup section above, you should have PowerShell Core installed.61 62```powershell63Import-Module ./build.psm164Start-PSBuild -UseNuGetOrg65```66 67> The PowerShell project by default references packages from the private Azure Artifacts feed, which requires authentication. The `-UseNuGetOrg` flag reconfigures the build to use the public NuGet.org feed instead.68 69Congratulations! If everything went right, PowerShell is now built.70The `Start-PSBuild` script will output the location of the executable:71 72`./src/powershell-unix/bin/Debug/net11.0/linux-x64/publish/pwsh`.73 74You should now be running the PowerShell Core that you just built, if you run the above executable.75You can run our cross-platform Pester tests with `Start-PSPester -UseNuGetOrg`, and our xUnit tests with `Start-PSxUnit`.76 