Install Midnight Commander on any? hosting account

The opportunity – your hosting account offers you shell access! 😀

The problem – they don’t have Midnight Commander installed! 😥

The background (skip to the solution!)

Ok for some of you, none of this is a problem.  You don’t have shell access on your shared hosting account – most don’t.  For others, you have shell access and Midnight Commander is installed already – great!  For other, you live and breathe for the Linux command line and your intimate knowledge of command syntax and Linux “innards” means you can create a symphony with your keyboard.

I, however, am not a Linux “heavy” and my shared hosting account with O2switch (which I think is a REAL deal, given what you get and the price you pay) provides shell access but no Midnight Commander.  I have done some Linux server management in a mixed platform environment and appreciate what Linux brings to the table but I’m a Windows guy and a visual person.  Consequently, when I see that I have shell access, I’m glad to have the ability to do certain things that simple ftp access doesn’t give me.  On the other hand, given ONLY a command line, my productivity plummets.  Don’t get me wrong, I appreciate what can be done with a command line.  I once worked on a mini computer where the only access was the command line for commands, navigating and editing.  I loved it – but I was young and that was my job.  I could afford to learn on the job and really get good and fast.  Now I’ve got too many fish to fry to learn another environment when I’m not in it all the time.  So for those of us who live MOSTLY in a non-Linux environment, a visual environment helps a LOT.

The problem (when the sys admins won’t install Midnight Commander for you) is that Midnight Commander doesn’t have a set of pre-compiled binaries sitting around for you to run.  It depends heavily on system libraries and thus is typically dynamically linked for the distribution where it will run or is compiled from source into the environment where it will run.  By default it installs in directories to which a shared hosting client doesn’t have access.   Even the ONE statically-linked pre-compiled binary which I found on the internet did not work except when running from a directory to which I didn’t have access! 🙄

My issues were mostly in two areas:

  1. Navigation – the basic need for a file manager – the felt need for which things like Norton Commander came into existence!
  2. File Editing – I had access to vim and nano and neither of these are what I’d call “intuitive”.  I’m not calling them “powerless”

I searched high and low and couldn’t find a solution.  I thought I’d try and compile it from source.  The compilers are NOT available to client accounts so I needed to compile elsewhere and then copy the executable binary to my hosting account and see if that would work.  I couldn’t easily figure out what distribution O2switch used for their servers as none of those discovery commands worked.  I finally asked them and they let me know that it was a CentOS derivative. So I installed a CentOS distro in a VM on my Windows machine.  Not that I did everything right but that was one of the hardest distros to work with.  Then I tried to see if I could compile and then static link on a Ubuntu distro in order to have a fully static-linked binary that, theoretically, I could drop in and run. I’d never compiled on a Linux machine so there were things that made sense from days compiling on IBM mainframes but there was a lot that I didn’t get and I was really going around in circles.

I looked for other ncurses-based file managers and/or editors.  I got Ranger to work, but it was WAY different than what I was used to while it helped me navigate a little bit, it still required a knowledge of a set of commands (it has a vi-based interaction) that I simply didn’t have and that were NOT intuitive from my background.  I tried to get the Diakonos editor to work (written in Ruby), but I don’t know Ruby at all and I barely got anything to run and the system-dependencies it had required that I try to make an older version run…blah, blah, blah – just a mess!

So I finally went to the mailing list of the Midnight Commander project to ask the experts.  I found THE resource that I needed in Erdmut Pfeifer on that list.  He gave me the foundation for…

The Solution!

Read the details of my conversation on the mailing list on this thread.  That will give you more background on what I did and especially on the solution that Erdmut was able to give me.  Here is the essence of his answer to me:

You don’t necessarily need to create a statically linked version to get
it to run on a different box. just pack up all required shared libs (use
ldd” to find out which) plus the dynamic loader itself. The dynamic
loader is normally invoked indirectly via the system, but nothing keeps
you from calling it directly, passing it the name of the dynamically
linked binary to run and the directory where the packed-up libs reside –
see “man ld.so” for details (“ld.so” is the generic name of the dynamic
loader, the actual name on today’s 64-bit boxes is typically
ld-linux-x86-64.so.2, which itself is a symlink to ld-<version>.so).
The loader is a statically linked binary, and thus doesn’t need any
libs itself.
 
As I found myself needing something like this rather frequently, I’ve
put together a little Perl script which automates these steps.

So I got his script (which you can find in the thread on the mailing list) and it worked!  I had to keep tweaking some things to get it just right for my environment, but I got it to the point where I could ssh to my shell session and then type “mc” and I was in an environment that I knew and I could be productive.

Here are the steps I took to make it work in the O2switch environment. YMMV in other environments!  (check the comments below to see where people have gotten this to work).

Also this was back in September 2016 so I’ve forgotten a bit of what I did and some of my notes are not as helpful to me at the moment, but I think they’ll get the persistent folks going in the right direction.

  1. I followed Erdmut’s directions in the thread (so theoretically you don’t have to, but it might be good to review it if you run into problems)
  2. Used mc from CentOS 6.8 package installation (it’s version 4.7.0.2)
  3. Added /usr and /etc parts (oops – I don’t totally remember what this means!  I think it’s creating a /usr and /etc structure in my local “mc” directory, which I named “mymc”, and copying in the files from the package installation that would normally be in the root “/usr” and root “/etc” directory structures in a typical system-wide installation)
  4. Ran strace -o ~/ztrace.txt -e trace=file ./mc and reviewed the file not found output to see what needed to be fixed (Unfortunately, I can’t help you with what needs to be fixed in your environment.  However, I just did this on Bluehost and lo and behold, just running this strace actually brought up Midnight Commander! ~/ztrace.txt WAS created and has lots of No such file or directory lines but it still works.  So perhaps certain functions won’t work.  Hard to say at this point.)
  5. cp ~/mymc/etc/mc/Syntax ~/mymc/etc
  6. cp ~/mymc/etc/mc/mc.lib ~/mymc/etc
  7. cp ~/mymc/etc/mc/mc.menu ~/mymc/etc
  8. cp ~/mymc/usr/share/mc/skins ~/mymc/etc
  9. cp ~/mymc/etc/mc/filehighlight.ini ~/mymc/etc
  10. cp ~/mymc/etc/mc/mc.keymap ~/mymc/etc
  11. cp ~/mymc/usr/share/mc/mc.hint ~/mymc/etc/mc.hint.  (the "." at the end is important!) (this brings the prompt)
  12. cp ~/mymc/usr/share/mc/mc.hlp ~/mymc/etc/mc.hlp. (the "." at the end is important!)
  13. cp ~/mymc/etc/mc/mc.ext ~/mymc/etc
  14. cp ~/mymc/usr/share/mc/syntax ~/mymc/etc
  15. Tried to redo mcedit, mcview symbolic links (this still isn’t working yet – i.e. I don’t have the “mcedit” and “mcview” commands.  The editor and viewer work just fine but I can’t access them via “mcedit” and “mcview”)
  16. Below, I’m including a zipped up version of “~/mymc” which may work right out of the box.  I have it unzipped into the root of my home directory.  I would suggest doing the same.  It is all contained in a folder mymc so you won’t be scattering a zillion files at your root.
  17. Make symbolic link to ~/mymc/mc so that I can run ./mc to start (might not have to do this if you do the following)
  18. Place the following in ~/.bashrc so that I can simply type “mc” to start
    PATH=$PATH:$HOME/mymc
    export PATH
  19. had to change putty’s translation settings to ISO-8859-1:1998 (Latin-1, West Europe) to make the lines correct.  This is dependant on what your server’s settings are.  It’ll likely be either UTF-8 or ISO-8859-1:1998 (Latin-1, West Europe)

Here’s a zipped copy of my directory “mymc” with everything you need (normally) to run Midnight Commander 4.7.0.2 as an O2switch client.  You’ll have to do the path work afterward to make it more easily executable. It may work for other environments. Please let me know if it does!

Download here ==> mymc.zip

2020-05-09 Edit: Got this working on Bluehost!

Posted in Computers and tagged , , , , , , , , , , , , , , .

10 Comments

  1. Thank you for this solution, it worked for me with your zipped mc like a charm! As a matter of fact, my hosting is HostGator and it worked with your binaries exactly as explained in the article.

  2. Vladimir,
    Thanks for the good news! Glad it worked for you and glad that it works in another environment as well. Happy mc-ing!
    David

  3. Hi David,

    just had to extract the package and execute the mc binary. That’s all.
    The hosting provider is Rackspeed.

  4. Hi David
    The zipped package worked perfectly with my hosting company GreenGeeks.
    Here are my steps:
    1. Download the ‘mymc.zip’ to the home folder using ‘wget -P ~/ https://david.leighweb.com/wp-content/uploads/mymc/mymc.zip
    2. Changed to home folder and unzipped it with ‘cd ~ && unzip mymc.zip’
    3. Added ‘alias mc=”~/mymc/mc”‘ to the file ‘~/.bashrc’
    Then re-logged in and tested ‘mc’.
    Worked perfectly.
    Many thanks for yours and Erdmut Pfeifer’s excellent work.

  5. Well, I just started working on a basic Digital Ocean Cloudways account for the first time. They don’t have mc installed and won’t install it for me, so I came back here and:
    1 – uploaded it to my account root directory
    2 – unzipped it (it created the mymc directory)
    3 – typed “./mymc/mc” and it worked!
    4 – in the ~/.profile file, I added the lines:
    PATH=”$PATH:$HOME/mymc”
    export PATH

    and now when I log in, I can simply type “mc” and it works. (not sure I need the “export PATH” line)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.