Swap is disk space used when RAM is full. It stops freezes on PCs with 2 to 4 GB of RAM.
1. Check current swap: swapon --show and free -h
2. Create a 4 GB swap file:
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
3. Keep it after restart: sudo nano /etc/fstab and add this line at the end:
/swapfile none swap sw 0 0
4. Check again with free -h.
Ubuntu already creates a swap file during install. If /swapfile already exists, resize it instead of making a second one. Swap on an old hard disk is slow: adding RAM or an SSD helps far more.