# How to install pkg offline?



## Kiwi_Birds (Nov 4, 2018)

Hello! This is my first time trying out FreeBSD on bare metal, as I want to use it as my main system (My second Hard Drive has Windows on it, for Games) and I do not have internet after the installation as I need to install this handy little software to get my phone to connect to my computer. I remember trying to do this once, but I had trouble since I don't know how to install pkg.txz offline. I have downloaded the file from here but I don't know how to install it as you need to use the pkg command to install things, correct? Thank you so much if you can help me out with this!


----------



## Beastie (Nov 4, 2018)

Welcome on board!

Yes, ports-mgmt/pkg needs to be bootstrapped. You'll have to do so manually. You can find the instructions on the wiki. It's near the end of the primer.

Once that is done, all packages can be installed locally using `# pkg add ./package.txz`.

Of course, for packages that actually have dependencies, you'll need the packages as well as all their dependencies in the same directory.


----------



## YuriiZ (Feb 25, 2021)

i'm new to FreeBSD. i have laptop and  there is no internet after installing OS. but any command wants download software instead of local install

so... >"."<
first boot after instalation OS (dvd 13.0beta3 in my case, there are some packages on dvd). mount my usb:
`# mount -t cd9660 /dev/da0s1 /mnt`

copy our instalation pkg(8) file:
`# cp /mnt/packages/FreeBSD:13:amd64/Latest/pkg.txz ~/`

disable signature checking and install full pkg (using preinstalled pkg(7)):
`#ee /etc/pkg/FreeBSD.conf`
signature_type: "fingerprints"
=>
signature_type: "none"

`#cd ~`
`#pkg add -f -y pkg.txz`

bootstrap pkg(8):
`# /usr/sbin/pkg`

and enable signature checking in /etc/pkg/FreeBSD.conf:
=> signature_type: "fingerprints"
now we can install all other packages from dvd:
`pkg add /mnt/packages/FreeBSD:13:amd64/All/bash-5.1.4.txz`

also you can download any packages on other PC and bring them to your PC without internet:
`#pkg fetch -o ~/folder/ -d sudo`


----------



## SirDice (Feb 25, 2021)

Try this:
`env PACKAGESITE=file:///mnt/packages/FreeBSD:13:amd64/ pkg bootstrap`


----------



## diizzy (Feb 25, 2021)

I've been looking to this too, there are some issues with using pkg add instead of pkg install in general but currently pkg install doesn't resolve local dependencies. It's being looked at but I have no idea when it's going to be resolved.


----------



## kpedersen (Feb 25, 2021)

I tend to do a mass fetch of the entire package repo every 6 months or so. You can either scrape the packages off http://pkg.freebsd.org/ (used to be easier with FTP) or you can use `pkg fetch -a` to grab everything.

https://www.freebsd.org/cgi/man.cgi?query=pkg-fetch

Once you have a big directory with everything in it, when you want to install something, just cd into the directory and run:


```
# pkg add <package>.txz
```

Dependencies will be resolved automatically and offline. I don't think so many people use it like this (kind of like pre-pkgng), but it works well offline and I dislike being tied to the internet (worst part about UNIX and Linux in my opinion).


----------



## YuriiZ (Feb 25, 2021)

kpedersen said:


> You can either scrape the packages off http://pkg.freebsd.org/



after months spent on reading handbook i found this link today, but folder All (in all branches) (example http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/ ) isn't available. is it ok? so i can't fetch any packages via windows, only i have to use VBox.


----------



## SirDice (Feb 25, 2021)

The directories are not browsable anymore, that's correct.


----------



## olli@ (Feb 25, 2021)

SirDice said:


> The directories are not browsable anymore, that's correct.


I have wondered about that myself, too.
Is there a way to download packages with an operating system other than FreeBSD (i.e. you can’t use `pkg fetch`)?


----------



## SirDice (Feb 25, 2021)

If you know the exact filename the downloads still work (or else pkg(8) would stop working too). But directory browsing has been turned off on the directory that has the files. Apparently this put too much of a load on the servers. 

I've been thinking about a solution, the first is to generate a static HTML page with links to the package files, those can be generated at the same time pkg-repo(8) runs, then you can still "browse" the file list but it won't be dynamically generated any more, which should alleviate the load on the server. 

The second solution is more a client side tool, to make a local copy of the repository. You can fetch the meta data and download each file individually based on the information in the meta data. Something like a "repocopy".


----------



## shkhln (Feb 25, 2021)

SirDice said:


> The directories are not browsable anymore, that's correct.


As documented in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247998#c1. (They should just enable caching instead of being silly. This is a bit obnoxious to set up, but whatever.)


----------



## ProphetOfDoom (Feb 25, 2021)

Incidentally, any recent iPhone or Android phone can act as a WiFi hotspot and you can connect your FreeBSD machine to your phone when you install FreeBSD. So there shouldn’t be any need for all this offline witchcraft!


----------



## bxbzq (Mar 1, 2021)

Hi AlexanderProphet,
I've been struggling with the network drivers on an old laptop TP T400, both wired and wireless, since yesterday. No luck. I suspect the hardware is already broken or in bad shape. For example, the wired network card even failed DHCP lease aquisition during installation.
I've seen several posts mentioning the iphone tethering, also in the handbook. From the description it seems easy work but i could not succeed. You mind sharing your experience to help me out?


----------



## ProphetOfDoom (Mar 2, 2021)

Hi bxbzq,
I’ve not ever had a WiFi card fail on me. Are you sure you’re setting the “regdomain” correctly for your country when installing FreeBSD? I had to experiment a bit. Even though I’m in the UK, I believe it was the USA setting that eventually worked for me. Sorry I can’t be more exact as I don’t have the installer in front of me - there are only about ten regdomains to choose from though.
This is how I turn my iPhone 11 into a wireless access point: tap settings (the grey cog) then tap “Personal hotspot”. Then switch on “Allow others to join”. It should say underneath what is your WiFi password.
The most important thing that I discovered is that you can’t really use the phone as a phone at the same time because when you navigate away from the “Personal hotspot” page the connection will usually be dropped. I think this is to save power/data but it’s very annoying. The connection also cuts out when the iPhone’s screen switches off, so you’ll probably also want to choose Settings -> Display and Brightness -> Auto-lock -> Never.
On Android it’s better because you can carry on using the phone as normal whilst it’s being a WiFi hotspot.


----------



## bxbzq (Mar 2, 2021)

AlexanderProphet said:


> Hi bxbzq,
> I’ve not ever had a WiFi card fail on me. Are you sure you’re setting the “regdomain” correctly for your country when installing FreeBSD? I had to experiment a bit. Even though I’m in the UK, I believe it was the USA setting that eventually worked for me. Sorry I can’t be more exact as I don’t have the installer in front of me - there are only about ten regdomains to choose from though.
> This is how I turn my iPhone 11 into a wireless access point: tap settings (the grey cog) then tap “Personal hotspot”. Then switch on “Allow others to join”. It should say underneath what is your WiFi password.
> The most important thing that I discovered is that you can’t really use the phone as a phone at the same time because when you navigate away from the “Personal hotspot” page the connection will usually be dropped. I think this is to save power/data but it’s very annoying. The connection also cuts out when the iPhone’s screen switches off, so you’ll probably also want to choose Settings -> Display and Brightness -> Auto-lock -> Never.
> On Android it’s better because you can carry on using the phone as normal whilst it’s being a WiFi hotspot.


Looks we are not on the same page.
By tethering, I’m referring to section 32.4 in the handbook, “Many cellphones provide the option to share their data connection overUSB (often called "tethering"). Thisfeature
uses one of RNDIS, CDC, or a custom Apple® iPhone®/iPad® protocol.
• Android™ devices generally use the urndis(4) driver.
• Apple® devices use the ipheth(4) driver.
• Older devices will often use the cdce(4) driver.
Before attaching a device, load the appropriate driver into the kernel:”


----------



## YuriiZ (Mar 2, 2021)

bxbzq said:


> I've seen several posts mentioning the iphone tethering, also in the handbook. From the description it seems easy work but i could not succeed. You mind sharing your experience to help me out?


Add those 3 modules to /boot/loader.conf, than reboot.

```
if_urndis_load="YES"
if_cdce_load="YES"
if_ipheth_load="YES"
```

Connect your phone to your wifi.
Connect your phone via usb cable to your laptop.
Open phone's Settings > Network & Internet > Hotspot & Tethering > USB tethering [enable it]
Check your new network interface:
`# ifconfig`
You might see at least two interfaces > lo0 and ue0.
Add DHCP client on your new interface:
`# dhclient ue0`
Check connection:
`# ping -c 4 1.1.1.1`

I have two android phones: Freetel (v5 android) and OnePlus6 (v11 android). I didn't get internet through OnePlus, but the old phone gave me successful connect.


----------



## bxbzq (Mar 5, 2021)

YuriiZ said:


> Add those 3 modules to /boot/loader.conf, than reboot.
> 
> ```
> if_urndis_load="YES"
> ...


I tried iphone 7 and iphone 11, neither of them worked. There was no ue0 interface detected, but usb connection info did show up. Will try to find an android phone and give a try.


----------



## decuser (Mar 6, 2021)

kpedersen said:


> I tend to do a mass fetch of the entire package repo every 6 months or so. You can either scrape the packages off http://pkg.freebsd.org/ (used to be easier with FTP) or you can use `pkg fetch -a` to grab everything.
> 
> https://www.freebsd.org/cgi/man.cgi?query=pkg-fetch
> 
> ...



I dislike being tied to it too. I just wish the size of the repo was more manageable... 87GiB right now, wow  How about a 10GiB version?


----------



## olli@ (Mar 9, 2021)

AlexanderProphet said:


> Incidentally, any recent iPhone or Android phone can act as a WiFi hotspot and you can connect your FreeBSD machine to your phone when you install FreeBSD. So there shouldn’t be any need for all this offline witchcraft!


Of course you can do that when you install a random private machine at home.
 
But you cannot do that when you’re inside an isolated network that has no connection to the internet, and there are only certain ways to transfer data, e.g. by downloading them on a dedicated download server (usually Linux, sometimes Windows). I’ve worked many years as a consultant with a focus on security. During that time I’ve been to several companies that had internal networks with restrictions like that (and of course, using USB sticks was forbidden, and trying to tether with a mobile phone would have brought me into jail). When packages were still distributed via FreeBSD’s FTP servers, you could simply download the tgz/tbz/txz files on the download server, even if that was a Linux or Windows machine, then transfer the files to the internal network.

That doesn’t work anymore today, making it much more difficult to install FreeBSD in such security-sensitive networks. I guess most admins who consider using FreeBSD will just install Linux upon discovering that there is no easy way to download FreeBSD packages separately.


----------



## tingo (Mar 10, 2021)

olli@ said:


> But you cannot do that when you’re inside an isolated network that has no connection to the internet, and there are only certain ways to transfer data, e.g. by downloading them on a dedicated download server (usually Linux, sometimes Windows). I’ve worked many years as a consultant with a focus on security. During that time I’ve been to several companies that had internal networks with restrictions like that (and of course, using USB sticks was forbidden, and trying to tether with a mobile phone would have brought me into jail). When packages were still distributed via FreeBSD’s FTP servers, you could simply download the tgz/tbz/txz files on the download server, even if that was a Linux or Windows machine, then transfer the files to the internal network.
> 
> That doesn’t work anymore today, making it much more difficult to install FreeBSD in such security-sensitive networks. I guess most admins who consider using FreeBSD will just install Linux upon discovering that there is no easy way to download FreeBSD packages separately.


Or they will arrange to have a FreeBSD build / stage server added to the admin network (approved and verified of course) so they can download and / or build packages on it, for transfer to the isolated network.


----------

