## Paclet Distribution

We can distribute paclets in either of two ways. We can distribute a packed .paclet file directly or distribute via a server.

Whichever route we go, though, we'll first need the .paclet file.

### Creating a .paclet File

To create a .paclet file we use the PackPaclet function in the "PacletManager" context. We can call it one of two ways:

• PackPaclet[dir] creates a packed .paclet file from dir and places it in dir
• PackPaclet[dir, dest] creates a packed .paclet file from dir and places it in dest

Say, for the sake of argument, that I am Etienne Bernard and write the Machine Learning functionality packaged into Mathematica. I can find my paclet directory like

 dir = PacletFind["MachineLearning"][[1]]["Location"]

 "/Applications/Mathematica.app/Contents/SystemFiles/Components/MachineLearning"


Then this can be packed into a .paclet file like:

 paclet = PackPaclet[dir, \$TemporaryDirectory]

 "/private/var/folders/9t/tqc70b7d61v753jkdbjkvd640000gp/T/MachineLearning-1.1.0.paclet"


And now this can be distributed

### Direct Distribution

Once a paclet is packed it can be distributed directly as it. For instance, I can put this in on my Wolfram Cloud account:

 CopyFile[
paclet,
CloudObject["user:b3m2a1.testing/MachineLearning.paclet", Permissions->"Public"]
]//Most

 CloudObject[]


And now anyone could come along and install this with:

 PacletInstall@
"http://www.wolframcloud.com/objects/b3m2a1.testing/MachineLearning.paclet"


Often we want something a little more sophisticated, though.

## Paclet Servers

Paclet servers exist to make it easy to serve many paclets from the same location. The PacletManager indexes all the paclet servers available to it and figures out where to install paclets from if simply provided with a name. Therefore it's useful for us to be able to set up our own servers.

To do this we simply need to add a Paclets directory to our server and provide a compressed metadata file PacletSite.mz . Overall our server will look like:

 
Server
PacletSite.mz
Paclets
Paclet1-version1.paclet
Paclet1-version2.paclet
Paclet2-version1.paclet
...



### PacletSite.mz

The paclet manager indexes the paclets on the server by looking at PacletSite.mz , which is much like a PacletInfo.m file, except instead of containing a single Paclet expression it contains a PacletSite expression that bundles up a bunch of different Paclet expressions.

In all it'll look like:

 PacletSite[
Paclet[
Name->"MyPaclet1",
...
],
Paclet[
Name->"MyPaclet2",
...
],
...
]


Then this gets written to a file as an expression and ZIP compressed.

In general we don't need to handle this ourselves, though, as there's a function in the PacletManager that does this. If we call PacletManagerPackageBuildPacletSiteFiles on our target directory it will do this for us.

For instance, I could call:

 PacletManagerPackageBuildPacletSiteFiles@
ExpandFileName@"~/Documents/GitHub/GitHubServer"


And all of the files in the Paclets sub-folder will get indexed into a PacletSite.m and PacletSite.mz file.

### Setting Up a Paclet Server

Once the construction is done locally, the server should be served over HTTP if possible. Older versions of the PacletManager` failed to deal appropriately with HTTPS content.

I tend to serve mine via the Wolfram Cloud or GitHub.

An example of the former is here and the latter is here .