<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sysadmin on Douglas Domingos :: CompSci@UFCG</title><link>https://dougdomingos.netlify.app/tags/sysadmin/</link><description>Recent content in Sysadmin on Douglas Domingos :: CompSci@UFCG</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sun, 15 Sep 2024 13:34:18 -0300</lastBuildDate><atom:link href="https://dougdomingos.netlify.app/tags/sysadmin/index.xml" rel="self" type="application/rss+xml"/><item><title>Installing software in Linux, the "hard" way</title><link>https://dougdomingos.netlify.app/posts/installing-packages-in-opt/</link><pubDate>Sun, 15 Sep 2024 13:34:18 -0300</pubDate><guid>https://dougdomingos.netlify.app/posts/installing-packages-in-opt/</guid><description>Introduction Picture this: you&amp;rsquo;re setting up the packages and tools to develop your brand new application. Everything is going smooth, until you found out that one of the softwares you need is only avaliable as package of executable binaries, without any installers and nowhere to be found in your package managers. Seems like quite the overhead, right?
Well, not to worry! Because today we&amp;rsquo;re out to get our hands dirty and learn how to install ANY PACKAGE in a Linux system ‒ and you might just learn a few new tricks about Linux along the way.</description><content>&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>Picture this: you&amp;rsquo;re setting up the packages and tools to develop your brand new
application. Everything is going smooth, until you found out that &lt;strong>one of the
softwares you need is only avaliable as package of executable binaries&lt;/strong>,
without any installers and nowhere to be found in your package managers. Seems
like quite the overhead, right?&lt;/p>
&lt;p>Well, not to worry! Because today we&amp;rsquo;re out to get our hands dirty and learn how
to install &lt;strong>ANY PACKAGE&lt;/strong> in a Linux system ‒ and you might just learn a few
new tricks about Linux along the way.&lt;/p>
&lt;h2 id="i-housing-the-package">I. Housing the package&lt;/h2>
&lt;p>The first step to solve our problem is to define &lt;strong>where the package will be
stored in our system&lt;/strong>. In practice, you may use any directory you&amp;rsquo;d like, but
to keep things organized, let&amp;rsquo;s use the &lt;code>/opt&lt;/code> directory.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>The &lt;code>/opt&lt;/code> directory&lt;/strong> is reserved for installing software and packages that
are not part of the system&amp;rsquo;s core components, i.e, &lt;strong>not necessary for your
system to function&lt;/strong> properly.&lt;/p>
&lt;p>When installing your package, &lt;strong>you should create a new directory&lt;/strong>
(preferably with the package name, like &lt;code>/opt/&amp;lt;package_name&amp;gt;&lt;/code>) to &lt;strong>avoid
mixing up files&lt;/strong> of different packages.&lt;/p>
&lt;/blockquote>
&lt;p>You may have noticed that inside your package, there&amp;rsquo;s a &lt;code>/bin&lt;/code> directory that
contains some executable files. At this point, we can run these files, but we&amp;rsquo;ll
have to specify the full path of the file every time.&lt;/p>
&lt;h2 id="ii-make-your-package-avaliable-with-path">II. Make your package avaliable with &lt;code>$PATH&lt;/code>&lt;/h2>
&lt;p>To avoid having to pass the full path of the executables each time we run the
software, we&amp;rsquo;ll make use of the &lt;code>$PATH&lt;/code> environmental variable to &lt;strong>specify the
path of our installation&lt;/strong>.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>The &lt;code>$PATH&lt;/code> variable&lt;/strong> is a special shell variable that defines a &lt;strong>list of
directories where executable files are located&lt;/strong>. Each directory is
&lt;strong>delimited by a colon&lt;/strong> (&lt;code>:&lt;/code>)&lt;/p>
&lt;p>You may specify new directories in &lt;code>$PATH&lt;/code> by &lt;strong>exporting the variable with
the new value&lt;/strong> (&lt;code>export PATH=/new/dir/path:$PATH&lt;/code>).&lt;/p>
&lt;/blockquote>
&lt;p>Now, there are two ways of adding a executable to &lt;code>$PATH&lt;/code>:&lt;/p>
&lt;h3 id="adding-a-_symlink_-to-the-executables">Adding a &lt;em>Symlink&lt;/em> to the executables&lt;/h3>
&lt;p>&lt;em>Symlinks&lt;/em> are (roughly) &lt;strong>files that &amp;ldquo;point&amp;rdquo; to other file paths or
directories&lt;/strong>. This allows us to access files accross the file system (and even
other file systems), &lt;strong>without specifying the full path&lt;/strong>.&lt;/p>
&lt;p>You can create new &lt;em>symlinks&lt;/em> using the command &lt;code>ln -s TARGET LINK_NAME&lt;/code>, where:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;code>TARGET&lt;/code> is the &lt;strong>path of the file which the &lt;em>symlink&lt;/em> will point to&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>LINK_NAME&lt;/code> is the &lt;strong>path where the &lt;em>symlink&lt;/em> will be created&lt;/strong>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>To make it avaliable in &lt;code>$PATH&lt;/code>, we may &lt;strong>create a &lt;em>symlink&lt;/em> inside a directory
that is already in &lt;code>$PATH&lt;/code>&lt;/strong>. In this case, let&amp;rsquo;s use the &lt;code>/usr/local/bin&lt;/code>
directory to store our &lt;em>symlink&lt;/em>.&lt;/p>
&lt;p>To create our &lt;em>symlink&lt;/em>, simply run the following comman:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Replace the placeholders with the proper names of your directories/files&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ln -s /opt/&amp;lt;package_name&amp;gt;/bin/&amp;lt;filename&amp;gt; /usr/local/bin/&amp;lt;filename&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Once created, the executable will be avaliable in your shell. Try it out by
&lt;strong>typing the name of the &lt;em>symlink&lt;/em> in your terminal&lt;/strong>.&lt;/p>
&lt;h4 id="trade-offs-of-using-_symlinks_">Trade-offs of using &lt;em>symlinks&lt;/em>&lt;/h4>
&lt;p>This approach is &lt;strong>pretty straightforward and easy to setup&lt;/strong>. We don&amp;rsquo;t need to
edit the value of &lt;code>$PATH&lt;/code>, thus &lt;strong>avoiding possible configuration errors&lt;/strong>.
Also, by placing the &lt;em>symlink&lt;/em> inside &lt;code>/usr/local/bin&lt;/code>, we make it &lt;strong>avaliable
for all users of the system&lt;/strong>.&lt;/p>
&lt;p>Unfortunately, there are also drawbacks. If you need to add multiple
executables, you&amp;rsquo;ll need do &lt;strong>create one &lt;em>symlink&lt;/em> per executable&lt;/strong>. You may
&lt;strong>create a &lt;em>symlink&lt;/em> to the &lt;code>/bin&lt;/code> directory&lt;/strong> of the package, but you&amp;rsquo;ll still
need to &lt;strong>specify the name of the executable&lt;/strong>.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Links in Linux&lt;/strong>&lt;br>
Links are a powerful tool in Linux, allowing you to &lt;strong>create shortcuts between
files and directories&lt;/strong>, &lt;strong>organizing your files easily&lt;/strong>, and much more. I
recommend reading this
&lt;a href="https://www.redhat.com/sysadmin/linking-linux-explained">RedHat post about linking in Linux&lt;/a>.&lt;/p>
&lt;/blockquote>
&lt;h3 id="adding-the-package-directory-to-path">Adding the package directory to &lt;code>$PATH&lt;/code>&lt;/h3>
&lt;p>If you want a more &lt;strong>robust solution&lt;/strong>, you may effectivelly edit the &lt;code>$PATH&lt;/code>
variable to &lt;strong>include your package directory&lt;/strong>. For that, we&amp;rsquo;ll need to &lt;strong>create
a configuration file&lt;/strong> to export our updated &lt;code>$PATH&lt;/code>.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>The &lt;code>/etc/&lt;/code> directory&lt;/strong> contains configuration files of system applications,
e.g. service management, network, SSH, and many more. Be careful when making
changes to files here.&lt;/p>
&lt;/blockquote>
&lt;p>Similar to &lt;code>/opt&lt;/code>, Linux also has a directory for &lt;strong>storing system-wide
configuration files: the &lt;code>/etc&lt;/code> directory&lt;/strong>. Actually, there&amp;rsquo;s the &lt;code>/etc/opt&lt;/code>
directory, which is intended to store configuration files for &lt;strong>applications
installed in &lt;code>/opt&lt;/code>&lt;/strong>.&lt;/p>
&lt;p>To create the configuration file, head to &lt;code>/etc/opt&lt;/code> and create a new file,
named as &lt;code>&amp;lt;package_name&amp;gt;rc&lt;/code>. Inside it, paste the following code and replace the
placeholders with the correspondent paths:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Replace &amp;#34;PACKAGE_HOME&amp;#34; with the name of your package&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>export PACKAGE_HOME&lt;span style="color:#f92672">=&lt;/span>/opt/&amp;lt;package_dir&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>export PATH&lt;span style="color:#f92672">=&lt;/span>$PACKAGE_HOME/bin:$PATH
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>To load the settings into your shell session, run
&lt;code>source /etc/opt/&amp;lt;config_file&amp;gt;&lt;/code> and check your &lt;code>$PATH&lt;/code> variable with
&lt;code>echo $PATH&lt;/code>. If the directory of your package is there, your configuration file
is working.&lt;/p>
&lt;p>Now, you might have noticed that &lt;strong>the configurations aren&amp;rsquo;t loaded
automatically&lt;/strong> when you open a new terminal. To address this, simply add this
configuration to one of the following files:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># This loads &amp;#34;PACKAGE&amp;#34; into $PATH&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span> -f /etc/opt/&amp;lt;config_file&amp;gt; &lt;span style="color:#f92672">]&lt;/span> &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> source /etc/opt/&amp;lt;config_file&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>
&lt;p>For &lt;strong>only one user&lt;/strong>, append the load configuration at the end of &lt;code>~/.bashrc&lt;/code>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>For &lt;strong>all users&lt;/strong>, create a shell script (with the &lt;code>.sh&lt;/code> suffix) in
&lt;code>/etc/profile.d/&lt;/code> with the load configuration&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h4 id="trade-offs-of-using-path">Trade-offs of using &lt;code>$PATH&lt;/code>&lt;/h4>
&lt;p>One advantage of this approach is that &lt;strong>every executable inside the &lt;code>/bin&lt;/code>
directory will be avaliable&lt;/strong> in your shell. Also, you may choose to &lt;strong>make it
avaliable for only one user or for all users&lt;/strong>, by simply placing the load
configuration in a different file.&lt;/p>
&lt;p>However, &lt;strong>tweaking with the &lt;code>$PATH&lt;/code> variable may break your shell
configuration&lt;/strong> if you&amp;rsquo;re not careful enough. The same goes for editing files
inside &lt;code>/etc/profile.d&lt;/code>; it&amp;rsquo;s best to create a new file rather than edit an
existing one.&lt;/p>
&lt;h2 id="iii-updating-the-desktop-menu-bonus">III. Updating the desktop menu (BONUS)&lt;/h2>
&lt;p>If you’re installing an application with a graphical interface (not CLI-based),
you’ll likely want to add it to your desktop menu for easier access. In this
case, we&amp;rsquo;ll need to take an extra step.&lt;/p>
&lt;p>The entries in your desktop menu are located in the &lt;code>/usr/share/applications&lt;/code>
directory. Each application has a &lt;code>.desktop&lt;/code> entry file, containing settings for
how it is displayed in the menu.&lt;/p>
&lt;p>To add a desktop entry file for your application:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>Create a new &lt;code>.desktop&lt;/code> entry file with the name of your application&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Open the file and add the following configuration, replacing the placeholders
with the correct settings:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span>Desktop Entry&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Version&lt;span style="color:#f92672">=&lt;/span>1.0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Type&lt;span style="color:#f92672">=&lt;/span>Application
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Name&lt;span style="color:#f92672">=&lt;/span>&amp;lt;APP_NAME&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Icon&lt;span style="color:#f92672">=&lt;/span>/opt/&amp;lt;PACKAGE_NAME&amp;gt;/&amp;lt;ICON_FILE&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Exec&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;/opt/&amp;lt;PACKAGE_NAME&amp;gt;/&amp;lt;EXEC_FILE&amp;gt;&amp;#34;&lt;/span> %f
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Comment&lt;span style="color:#f92672">=&lt;/span>&amp;lt;APP_DESCRIPTION&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Categories&lt;span style="color:#f92672">=&lt;/span>&amp;lt;KEYWORD1;KEYWORD2;&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>Save the file and run &lt;code>sudo update-desktop-database&lt;/code>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>Now, the application is avaliable in your app menu, without the need to start it
through the terminal.&lt;/p>
&lt;h2 id="summary">Summary&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Install your package in the &lt;code>/opt&lt;/code> directory&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Use &lt;em>symlinks&lt;/em> or edit your &lt;code>$PATH&lt;/code> variable to include the package
executables for an user or all the system&lt;/p>
&lt;/li>
&lt;li>
&lt;p>If the package is not CLI-based, add a &lt;code>.desktop&lt;/code> entry file at
&lt;code>/usr/share/applications&lt;/code> to add the package to your desktop menu&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>Although application support for Linux platforms is pretty decent today, you&amp;rsquo;ll
eventually come across a situation like the one we&amp;rsquo;ve discussed here. Also, you
can automate this process by creating shell scripts to setup the files for you.&lt;/p>
&lt;p>Well, that&amp;rsquo;s it. Until next time! &amp;#x1f44b;&lt;/p></content></item></channel></rss>