Files

75 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

# Build PowerShell on Linux
2017-04-11 09:44:43 -07:00
This guide will walk you through building PowerShell on Linux.
2016-07-18 21:29:17 +02:00
We'll start by showing how to set up your environment from scratch.
## Environment
These instructions are written assuming Ubuntu 24.04 LTS (the CI uses ubuntu-latest).
2016-07-18 21:29:17 +02:00
The build module works on a best-effort basis for other distributions.
### Git Setup
2016-04-13 16:21:23 -07:00
2017-04-11 09:44:43 -07:00
Using Git requires it to be set up correctly;
2016-08-06 15:53:51 -07:00
refer to the [Working with the PowerShell Repository](../git/README.md),
2024-07-31 12:41:15 -07:00
[Readme](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md).
2016-04-13 16:21:23 -07:00
2016-07-18 21:29:17 +02:00
**This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it.**
2016-04-13 16:21:23 -07:00
### Toolchain Setup
We use the [.NET Command-Line Interface][dotnet-cli] (`dotnet`) to build the managed components.
2017-04-11 09:44:43 -07:00
Installing the toolchain is as easy as running `Start-PSBootstrap` in PowerShell.
2016-07-18 21:29:17 +02:00
Of course, this requires a self-hosted copy of PowerShell on Linux.
Fortunately, this is as easy as [downloading and installing the package](https://learn.microsoft.com/en-us/powershell/scripting/install/install-other-linux#binary-archives).
The `./tools/install-powershell.sh` script will also install the PowerShell package.
2016-04-13 16:21:23 -07:00
In Bash:
2016-07-15 18:34:33 -07:00
```sh
./tools/install-powershell.sh
2016-07-15 18:34:33 -07:00
pwsh
2016-04-13 16:21:23 -07:00
```
You should now be in a PowerShell console host that is installed.
2016-07-18 21:29:17 +02:00
Just import our module, bootstrap the dependencies, and build!
2016-07-15 18:34:33 -07:00
2016-04-13 16:21:23 -07:00
In PowerShell:
```powershell
Import-Module ./build.psm1
Start-PSBootstrap -Scenario Both
2016-04-13 16:21:23 -07:00
```
The `Start-PSBootstrap` function does the following:
- Installs build dependencies and packaging tools via `apt-get` (or equivalent package manager)
- Downloads and installs the .NET SDK (currently version 10.0.100-rc.1) to `~/.dotnet`
2016-07-18 21:29:17 +02:00
If you want to use `dotnet` outside of `Start-PSBuild`, add `~/.dotnet` to your `PATH` environment variable.
[dotnet-cli]: https://learn.microsoft.com/dotnet/core/tools/
## Build using our module
2017-04-11 09:44:43 -07:00
We maintain a [PowerShell module](../../build.psm1) with the function `Start-PSBuild` to build PowerShell.
Since this is PowerShell code, it requires self-hosting.
If you have followed the toolchain setup section above, you should have PowerShell Core installed.
2016-04-04 18:52:54 -07:00
```powershell
Import-Module ./build.psm1
2024-07-31 12:41:15 -07:00
Start-PSBuild -UseNuGetOrg
```
> 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.
2016-04-04 18:52:54 -07:00
Congratulations! If everything went right, PowerShell is now built.
The `Start-PSBuild` script will output the location of the executable:
2016-07-15 18:34:33 -07:00
`./src/powershell-unix/bin/Debug/net11.0/linux-x64/publish/pwsh`.
You should now be running the PowerShell Core that you just built, if you run the above executable.
2024-07-31 12:41:15 -07:00
You can run our cross-platform Pester tests with `Start-PSPester -UseNuGetOrg`, and our xUnit tests with `Start-PSxUnit`.