# \`swift package install\` Subcommand

**URL:** <https://forums.swift.org/t/swift-package-install-subcommand/58065>\
**Category:** Package Manager\
**Created:** [June 12, 2022, 1:34pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065 "2022-06-12T13:34:24Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![NSXPCConnection](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsxpcconnection/32/31019_2.png) [@NSXPCConnection](https://forums.swift.org/u/NSXPCConnection)\
**Post date:** [June 14, 2022, 9:48pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/21 "2022-06-14T21:48:08Z")

</div>

And use it in what way though? This is an executable

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [June 14, 2022, 9:55pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/22 "2022-06-14T21:55:16Z")

</div>

This is basically what I mean:

```nohighlight
swift package install --url https://somewhere.tld/some/package
swift package install --id some.package
swift package install --path /Users/Someone/Development/some/package

```

All of the plumbing for it should already be there.

---

<div class="post-metadata">

**Author:** ![NSXPCConnection](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsxpcconnection/32/31019_2.png) [@NSXPCConnection](https://forums.swift.org/u/NSXPCConnection)\
**Post date:** [June 14, 2022, 9:57pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/23 "2022-06-14T21:57:02Z")

</div>

I see! I’ll integrate —path sometime but how would —id work?

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [June 14, 2022, 10:07pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/24 "2022-06-14T22:07:41Z")

</div>

I am basically mirroring [these](https://github.com/apple/swift-package-manager/blob/3799095f1181c0199b4b7a926f6f208fa333f610/Sources/PackageDescription/PackageDependency.swift#L33-L49) from the manifest.

All you would be doing is asking SwiftPM’s existing fetch code to put it in `tmp` or wherever you are working instead of inside `.build`.

Any versioning analysis you would need is likewise already implemented for the sake of resolution (including security checksums).

---

<div class="post-metadata">

**Author:** ![NSXPCConnection](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsxpcconnection/32/31019_2.png) [@NSXPCConnection](https://forums.swift.org/u/NSXPCConnection)\
**Post date:** [June 14, 2022, 11:00pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/25 "2022-06-14T23:00:15Z")

</div>

@stackotter @SDGGiesbrecht local support, added and tested, [here](https://github.com/SerenaKit/swift-package-manager/commit/2069d14167a5b6b3bc254f3565ecbf8366b6465a).

---

<div class="post-metadata">

**Author:** ![stackotter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stackotter/32/20670_2.png) [@stackotter](https://forums.swift.org/u/stackotter)\
**Post date:** [June 15, 2022, 5:04am UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/26 "2022-06-15T05:04:11Z")

</div>

I can already see this being so useful for distributing Swift tools. At the moment I'm using Mint and it's a bit cumbersome when overriding installed versions with local development builds. Also, not everyone has Mint installed, so having the functionality built into SwiftPM will make installing tools even simpler.

I still think that the install command should support local git-less packages, they could be versioned using sha checksums. It would be slower than commit hashes, but at least it would be able to avoid unnecessarily rebuilding local packages when updating them from a script or something.

---

<div class="post-metadata">

**Author:** ![NSXPCConnection](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsxpcconnection/32/31019_2.png) [@NSXPCConnection](https://forums.swift.org/u/NSXPCConnection)\
**Post date:** [June 15, 2022, 1:34pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/27 "2022-06-15T13:34:01Z")

</div>

@stackotter @SDGGiesbrecht Update: Local support for gitless repos added: [Add install-package support for gitless repos, add --force flag to up… · SerenaKit/swift-package-manager@62cb55b · GitHub](https://github.com/SerenaKit/swift-package-manager/commit/62cb55b133f0289b62b0e30d5a15de39dee2bba5)

---

<div class="post-metadata">

**Author:** ![NSXPCConnection](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsxpcconnection/32/31019_2.png) [@NSXPCConnection](https://forums.swift.org/u/NSXPCConnection)\
**Post date:** [June 15, 2022, 1:34pm UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/28 "2022-06-15T13:34:24Z")

</div>

Oh, and another update, pr opened at [Add Subcommands to install, update, and remove packages. by SerenaKit · Pull Request #5591 · apple/swift-package-manager · GitHub](https://github.com/apple/swift-package-manager/pull/5591)

---

<div class="post-metadata">

**Author:** ![samdeane](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/samdeane/32/2175_2.png) [@samdeane](https://forums.swift.org/u/samdeane)\
**Post date:** [July 27, 2022, 10:26am UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/29 "2022-07-27T10:26:30Z")

</div>

This is cool.

A possible enhancement:

Once you've fetched the package you're going to build & install, run `swift package plugin --list` on it, and look for command plugins with known names, such as `pre-install`, `post-install`. If they are found, invoke them.

This would provide a clean mechanism for pre/post-install hooks and other more complicated installation stuff. There is a security trade-off, of course, but then that's already inherent in installing an open-source tool in the first place, since you're presumably going to run it once you've installed it.

(I confess that I've not looked at the code, so maybe you're doing something like this already, in which case I will shut up...!)

---

<div class="post-metadata">

**Author:** ![samdeane](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/samdeane/32/2175_2.png) [@samdeane](https://forums.swift.org/u/samdeane)\
**Post date:** [July 27, 2022, 10:32am UTC](https://forums.swift.org/t/swift-package-install-subcommand/58065/30 "2022-07-27T10:32:32Z")

</div>

Part of the motivation for that suggestion is that I built something [here](https://github.com/elegantchaos/XPkg) which acts a kind of general-purpose package manager that I use to install things on my machines, but also to configure things.

So for example I might install things like my "xcode support" package, which adds a bunch of scripts and aliases into known locations, but also sets up some symbolic links for stuff like my standard Xcode templates.

I built my tool _on top_ of SPM, and it leverages SPM to handle versions and dependencies. That works, but I still have to do a bootstrap installation of my tool. Having the same abilities built in to SPM would be one step closer to nirvana! For that to work though I need to not just install my "Xcode support" package, but then invoke it to perform the rest of the setup. Likewise when uninstalling, I need to be able to invoke something to clean up.

[Previous page](https://forums.swift.org/t/swift-package-install-subcommand/58065.md?page=1)
