Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux snap command

Linux snap command

Linux Command Reference Linux Command Reference


snap is a software packaging and deployment system developed by Canonical for Linux distributions. It provides a secure and reliable way to install, update, and manage applications.

Core features of snap

  1. Containerized applications: Each snap application runs in its own sandbox environment
  2. Automatic updates: Supports automatic background updates of applications
  3. Cross-distribution: The same snap package can run on multiple Linux distributions
  4. Dependency inclusion: All dependencies are packaged in the snap, avoiding system dependency conflicts

The difference between snap and traditional package management

Feature snap Traditional package management (apt/yum)
Dependency Management Self-contained System-level sharing
Update mechanism Automatic rolling updates Requires manual updates
Isolation Strong isolation Weak isolation
Cross-distribution support Supported Not supported
Rollback capability Supported Limited support

Basic syntax of the snap command

The basic syntax structure of the snap command is as follows:

snap [命令] [选项] [包名]

Overview of common commands


Detailed usage of the snap command

Install a snap package

sudo snap install 

Common options:

Example:

sudo snap install code --classic  # 安装 VS Code

List installed snap packages

snap list

Example output:

Name    Version    Rev    Tracking       Publisher    Notes

code    v1.70.2    xxxxx  latest/stable  vscode✓      classic

Search for snap packages

snap find 

Example:

snap find telegram

Update snap packages

Update a single package:

sudo snap refresh 

Update all packages:

sudo snap refresh

Remove a snap package

sudo snap remove 

View snap package information

snap info 

The output contains detailed information such as version, channel, and description.


Advanced snap features

Channel management

snap provides multiple release channels:

Example

graph LR

    A[Edge] --> B[Beta]

    B --> C[Candidate]

    C --> D[Stable]

Command to switch channels:

sudo snap refresh  --channel=

Version rollback

If a new version has problems, you can roll back to a previous version:

sudo snap revert 

Service management

For snap packages that provide services:

Check service status:

snap services

Start/stop a service:

Example

sudo

snap start

sudo

snap stop


Practical Application Examples

Example 1: Install and run Nextcloud

Example

Install Nextcloud

sudo

snap

install

nextcloud

Configure the administrator account

sudo

nextcloud.manual-install  

Get the access address

sudo

nextcloud.occ config:system:get overwrite.cli.url

Example 2: Install a development toolchain

Example

Install the Go language

sudo

snap

install

go

--classic

Install Node.js

sudo

snap

install

node

--channel

=

14

/

stable

--classic

Install Docker

sudo

snap

install

docker


Common Problem Solutions

Problem 1: snap applications start slowly

Solutions:

Example

Preload snap core components

sudo

snap

install

core

sudo

snap

install

snapd

Restart the snap service

sudo

systemctl restart snapd

Problem 2: Permission errors

For applications that need to access system resources, use:

Example

Connect the required interfaces

sudo

snap connect : :

For example, allow VLC to access removable devices

sudo

snap connect vlc:removable-media

Problem 3: Disk space usage

Clean up old versions:

Example

Set the number of versions to keep (default is 3)

sudo

snap

set

system refresh.retain=

2

Manual cleanup

sudo

snap system

prune


Best Practice Recommendations

  1. Prefer the stable channel: for use in production environments --channel=stable
  2. Regularly clean up old versions: to avoid using too much disk space
  3. Use connected interfaces wisely: grant only the necessary system permissions
  4. Monitor automatic updates: for important services, consider manually controlling update times
  5. Combine with traditional package management: for critical system components, it is still recommended to use the distribution's official repositories

By mastering snap commands, you can manage applications on Linux more efficiently and enjoy the convenience and security of containerization.


Linux Command Reference Linux Command Reference