2017-11-01 23:55:46 +01:00
|
|
|
# Build PowerShell on Linux
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-04-11 18:44:43 +02: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.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
## Environment
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-04-11 18:44:43 +02:00
|
|
|
These instructions are written assuming the Ubuntu 14.04 LTS, since that's the distro the team uses.
|
2016-07-18 21:29:17 +02:00
|
|
|
The build module works on a best-effort basis for other distributions.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
### Git Setup
|
2016-04-14 01:21:23 +02:00
|
|
|
|
2017-04-11 18:44:43 +02:00
|
|
|
Using Git requires it to be set up correctly;
|
2016-08-07 00:53:51 +02:00
|
|
|
refer to the [Working with the PowerShell Repository](../git/README.md),
|
2016-07-18 21:29:17 +02:00
|
|
|
[README](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md).
|
2016-04-14 01:21:23 +02: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-14 01:21:23 +02:00
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
### Toolchain Setup
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-04-11 18:44:43 +02:00
|
|
|
We use the [.NET Command-Line Interface][dotnet-cli] (`dotnet`) to build the managed components,
|
|
|
|
and [CMake][] to build the native components.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-04-11 18:44:43 +02: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.
|
2016-04-14 01:21:23 +02:00
|
|
|
|
2017-04-11 18:44:43 +02:00
|
|
|
Fortunately, this is as easy as [downloading and installing the package](../installation/linux.md).
|
2017-11-03 16:47:26 +01:00
|
|
|
The `./tools/install-powershell.sh` script will also install the PowerShell package.
|
2016-04-14 01:21:23 +02:00
|
|
|
|
|
|
|
In Bash:
|
|
|
|
|
2016-07-16 03:34:33 +02:00
|
|
|
```sh
|
2017-11-01 23:55:46 +01:00
|
|
|
./tools/install-powershell.sh
|
2016-07-16 03:34:33 +02:00
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
pwsh
|
2016-04-14 01:21:23 +02:00
|
|
|
```
|
|
|
|
|
2017-11-01 23:55:46 +01: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-16 03:34:33 +02:00
|
|
|
|
2016-04-14 01:21:23 +02:00
|
|
|
In PowerShell:
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-04-14 01:21:23 +02:00
|
|
|
```powershell
|
2016-05-18 22:58:59 +02:00
|
|
|
Import-Module ./build.psm1
|
2016-04-14 01:21:23 +02:00
|
|
|
Start-PSBootstrap
|
|
|
|
```
|
|
|
|
|
|
|
|
The `Start-PSBootstrap` function does the following:
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2016-04-05 03:52:54 +02:00
|
|
|
- Adds the LLVM package feed
|
2016-07-18 21:29:17 +02:00
|
|
|
- Installs our dependencies combined with the dependencies of the .NET CLI toolchain via `apt-get`
|
2016-06-11 01:06:08 +02:00
|
|
|
- Uninstalls any prior versions of .NET CLI
|
2017-11-01 23:55:46 +01:00
|
|
|
- Downloads and installs the .NET Core SDK 2.0.0 to `~/.dotnet`
|
2016-06-11 01:06:08 +02:00
|
|
|
|
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.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-03-28 00:26:22 +02:00
|
|
|
[dotnet-cli]: https://github.com/dotnet/cli
|
2016-03-30 23:15:15 +02:00
|
|
|
[CMake]: https://cmake.org/cmake/help/v2.8.12/cmake.html
|
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
## Build using our module
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-04-11 18:44:43 +02: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.
|
2017-11-01 23:55:46 +01:00
|
|
|
If you have followed the toolchain setup section above, you should have PowerShell Core installed.
|
2016-04-05 03:52:54 +02:00
|
|
|
|
2016-03-30 23:15:15 +02:00
|
|
|
```powershell
|
2016-05-18 22:58:59 +02:00
|
|
|
Import-Module ./build.psm1
|
2016-03-30 23:15:15 +02:00
|
|
|
Start-PSBuild
|
|
|
|
```
|
2017-11-01 23:55:46 +01:00
|
|
|
|
2016-04-05 03:52:54 +02:00
|
|
|
Congratulations! If everything went right, PowerShell is now built.
|
|
|
|
The `Start-PSBuild` script will output the location of the executable:
|
2016-07-16 03:34:33 +02:00
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
`./src/powershell-unix/bin/Linux/netcoreapp2.0/linux-x64/publish/pwsh`.
|
2016-03-30 23:15:15 +02:00
|
|
|
|
2017-11-01 23:55:46 +01:00
|
|
|
You should now be running the PowerShell Core that you just built, if your run the above executable.
|
2016-07-18 21:29:17 +02:00
|
|
|
You can run our cross-platform Pester tests with `Start-PSPester`, and our xUnit tests with `Start-PSxUnit`.
|