Installing From Source

Not all programs you want to install will be available in your repositories. Also, you may not be lucky enough to be able to find a .debĀ  file for the program you want to install. Fortunately, installing from source is usually pretty simple. Let's try to install msnake which is a terminal based snake game

[bradr@localhost ~]$ git clone https://github.com/mogria/msnake

Then we can cdĀ  into the NerdFetch directory. And while the installation process is typically the same 3 steps ./configure , make , and make install , it is good practice to read the README, because there are always some options or differences.

[bradr@localhost ~]$ cd msnake
[bradr@localhost msnake]$ cat README
...
Change into the cloned git repository (or the folder where you extracted the zip file) and enter the following commands
to compile the game:

```console
mkdir build
cd build
cmake ..
make
```
...

So we see this want us to use cmake, which is fine. We may have to install that, as most Linux distros use the gcc c-compiler.

[bradr@localhost msnake]$ sudo apt install cmake
[bradr@localhost msnake]$ mkdir build && cd build
[bradr@localhost build]$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for wsyncup in /usr/lib/x86_64-linux-gnu/libcurses.so
-- Looking for wsyncup in /usr/lib/x86_64-linux-gnu/libcurses.so - found
-- Looking for cbreak in /usr/lib/x86_64-linux-gnu/libncurses.so
-- Looking for cbreak in /usr/lib/x86_64-linux-gnu/libncurses.so - found
-- Looking for nodelay in /usr/lib/x86_64-linux-gnu/libncurses.so
-- Looking for nodelay in /usr/lib/x86_64-linux-gnu/libncurses.so - found
-- Found Curses: /usr/lib/x86_64-linux-gnu/libncurses.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bradr/msnake/build

[bradr@localhost build]$ make
[  8%] Building C object CMakeFiles/msnake.dir/src/dialog.c.o
[ 16%] Building C object CMakeFiles/msnake.dir/src/effects.c.o
[ 25%] Building C object CMakeFiles/msnake.dir/src/events.c.o
[ 33%] Building C object CMakeFiles/msnake.dir/src/fruits.c.o
[ 41%] Building C object CMakeFiles/msnake.dir/src/game.c.o
[ 50%] Building C object CMakeFiles/msnake.dir/src/glog.c.o
[ 58%] Building C object CMakeFiles/msnake.dir/src/highscore.c.o
[ 66%] Building C object CMakeFiles/msnake.dir/src/main.c.o
[ 75%] Building C object CMakeFiles/msnake.dir/src/snake.c.o
[ 83%] Building C object CMakeFiles/msnake.dir/src/status-display.c.o
/home/bradr/msnake/src/status-display.c: In function ā€˜status_displayā€™:
/home/bradr/msnake/src/status-display.c:22:54: warning: format ā€˜%iā€™ expects argument of type ā€˜intā€™, but argument 6 has type ā€˜time_tā€™ {aka ā€˜long intā€™} [-Wformat=]
   22 |   mvprintw(0, game->columns - width, "%03iL|%05iP|%04is|%04iSCR",
      |                                                   ~~~^
      |                                                      |
      |                                                      int
      |                                                   %04li
......
   25 |       time(NULL) - game->started - game->paused,
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       
      |                                  |
      |                                  time_t {aka long int}
[ 91%] Building C object CMakeFiles/msnake.dir/src/time-helpers.c.o
[100%] Linking C executable msnake
[100%] Built target msnake


After this, we can lsĀ  and see that our files have been compiled and created.

[bradr@localhost build]$ ls
build  CMakeLists.txt  debian  LICENSE  makedeb.sh  README.md  src


Now all that's left is to install with make installĀ  which requires sudoĀ  privileges.

[bradr@localhost build]$ make install
[100%] Built target msnake
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/msnake


Now just run msnakeĀ  and play