{% extends "Default/default.html" %} {% block content %}

# {% block title %}dnf Tutorial{% endblock %}

## What is "dnf"?

DNF is a software package manager that installs, updates, and removes packages on RPM-based Linux distribution. For all of the detailed commands one can simply enter "dnf --help" into the terminal.

If you want to simply update the packages to the latest, you may do so using dnf on the dnf Package Update page.

Below will be a number of sections explaining how to: search for packages, update packages, add/remove packages, and an example of using packages.

## Search for Packages

The following command will show a list of all of the packages. There are a lot of packages so it is recommended to pipe this command into a file. You can also add an optional command afterwards of the package_name to narrow down the results. `dnf repoquery <package_name>`

## Update/Install Packages

To update the packages and install a specific one follow the following commands:

`dnf repoquery` `dnf install -y <package_name>`

Alternatively you can accomplish this on the webapp by going to the dnf Update page and selecting what packages you wish to update.

## Use Case Example

We will show an example of how to update, install, and then use one of the packages that we install. This example specifically will enable us to play the game OpenTyrian.

`dnf repoquery` `dnf install opentyrian` `opentyrian`

Now you will be able to play the game (only shows up on the desktop).

## Add/Remove Packages

In this section we will explain how to write a simple "Hello World" application, compile it, and create a RPM package with CMake, install/remove it with "dnf", and run it. This will demonstrate the ease of installing and removing packages with "dnf".

- Create a hello directory where you think is applicable. A recommendation could be /home/<username>/Desktop/hello.
- Install the rpm-build package using "dnf". CMake will use it to build the RPM package:
  `dnf install rpm-build`
- Write the "Hello World" application in hello.c in your created hello directory:
  `#include <stdio.h>
  int main(int argc, char *argv[])
  {
  printf("hello world\n");
  return 0;
  }`
- Write the CMakeLists.txt file in the same directory. This is like a Makefile but is used by CMake. The following CMakeLists.txt file is very minimalistic(but works):
  `cmake_minimum_required(VERSION 2.6)
  PROJECT(HelloWorld)
  ADD_EXECUTABLE(hello hello.c)
  INSTALL(TARGETS hello DESTINATION /usr/bin)
  SET(CPACK_GENERATOR "RPM")
  INCLUDE(CPack)`
- Build the application and the RPM package. Install the RPM package with "dnf". Run the application. Remove the RPM package with "dnf".
  `# Build
  mkdir build
  cd build
  cmake ..
  make package
  # Install package
  dnf install HelloWorld-0.1.1-Linux.rpm
  # Run
  hello
  # Remove package
  dnf remove helloworld`
- Congratulations, if everything worked you would have seen the "Hello World" printed and would have successfully learned how to use "dnf" (along with some CMake).

{% endblock %}