I have made a C program, but it depends on the ncurses library. So, when i give my code to anyone else, I have to ask him/her to install ncurses library first then only compile the code using the Makefile i provided.
However, I want to write a shell script which will automatically install ncurses if it is NOT already installed. So that I can simply ask my friend to run the script.
This is what i want the script to do ::
if(ncurses-dev package not installed)
sudo apt-get install ncurses-dev
I know it is a very basic question, but i dont know how to do it. I tried google search but could not find a simple tutorial which i could understand.
For fedora
if ! rpm -qa | grep -qw $package_name$; then
yum install $package_name
fi
For UBUNTU
#!/bin/sh
for package; do
dpkg -s "$package" >/dev/null 2>&1 && {
echo "$package is installed."
} || {
sudo apt-get install $package
}
done
This can be used for checking multiple packages as well.
To automatically install without user interaction on Debian(In your case Ubuntu), you could use the --force-yes --yes switches in your command line args list. Like so:
sudo apt-get --force-yes --yes install package
Related
I have a little problem to install Wine on my alpine image.
Here is my Dockerfile :
RUN dpkg --add-architecture i386 && sudo apt-get update
RUN sudo apt-get install software-properties-common python-software-properties
RUN sudo add-apt-repository ppa:ubuntu-wine/ppa
RUN sudo apt-get update
RUN sudo apt-get install wine1.8 winetricks
RUN sudo apt-get purge software-properties-common python-software-properties
RUN rm -rf /tmp/* /var/lib/apt/lists/* /root/.cache/*
CMD /bin/bash;
All seems to work well, but during the sudo apt-get install wine1.8 winetricks I have this EULA screen :
Of course I don't have the right to write "YES". I tried :
RUN echo "yes" | sudo apt-get install wine1.8 winetricks
RUN sudo apt-get -y install wine1.8 winetricks
What can I do ?
Note: In the interest of edification, I would love it if a more learned linux/docker user could explain the mechanics behind why my solution worked for me.
Possible Solution:
I encountered this exact problem. I must have tried every conceivable way to pass an argument via my Dockerfile that would accept the EULA; to include piping an echo of "yes" to the wine installation command, as you've tried, setting environment variables and so-on. So, you're not alone here. I did, however, find a very simple solution through experimentation.
It turns out that if you install the TrueType core fonts (the package the EULA is for) before installing wine, you can pass it the "yes" input like so and wine will never prompt for the EULA:
RUN echo "yes" | apt install ttf-mscorefonts-installer -y
I'm not sure why this is. I suspect that it's because installing wine installs several other packages/dependencies in the process, and the echo/pipe approach does not extend to all packages that wine attempts to install. Perhaps by installing the fonts separately, the wine installation script either disregards the package because it's already present, or some file within the font installation logs the EULA acceptance response.
Here's the contents of my Dockerfile. I'm on Ubuntu 16.04 LTS, using Docker version 18.02.0-ce, build fc4de44:
FROM ubuntu:16.04
RUN dpkg --add-architecture i386
RUN apt-get update -y
RUN echo "yes" | apt install ttf-mscorefonts-installer -y
RUN apt-get install wine -y
I see it's four months since this post was made, but if you haven't found a solution, I hope this helps!
Let's say that i want to install specific package from ubuntu repos, but all depends of codename. For example, on ubuntu 14.04 lts there is a package called librabbitmq1, and on ubuntu 16.04 librabbitmq4. Depends on codename i want to choose existing one.
"If ubuntu_codename=trusty install librabbitmq1
else
install librabbitmq4"
or something like this...
"If apt-get install librabbitmq1 returns 1 (or positive) install that, else install librabbitmq4"
A simple one-liner in bash could do the trick which works on the return-code(s) of the commands executed.
sudo apt-get install librabbitmq1 || echo "librabbitmq1 Installation failed" && sudo apt-get install librabbitmq4 || echo "librabbitmq4 Installation failed"
I'm doing a script which installs a tcl plugin.
But this tcl plugin require some additional tcl/tk libraries, so I was thinking about putting an APT-GET install command for installing these libraries.
Is there a way to use the APT-GET install command in a script (it can be Shell script, Perl or even Tcl)?
This is an example of how to do it with one line and assumes you are running the script with sudo or have appropriate privilege.
apt-get -qq update && apt-get -qq --yes --force-yes install tcl
-qq suppresses output unless an error occurs
--yes answers the prompt 'Do you want to continue? [Y/n]'
--force-yes installs packages that come from a private repository
Consider running apt-get update & earlier in the script. Check or wait for the job to finish before using apt-get install
You can list multiple packages on one line. Packages are installed in the order they are listed.
I try to install ruby and rails to start to learn ruby on rails.
I work on Windows. After many search and tries, I gave up and installed a fresh ubuntu 14 x64 in a VirtualBox.
I installed ruby with apt-get, but its files get spread all over the file system (/bin, /var...). So, I have to use always sudo and search all over the place when installing gems.
I would like, just like in windows, find a ruby tar.gz which I can decompress in a folder of mine, with all files at the same place, where I have the "control" over the files, and I can watch easily what it's hapenning while installing gems, rails, etc...
The problem : I cannot find any tar.gz (or similar archive) of ruby for linux which I simply can uncompress in a folder and work with it (I can manage the $path). The only one I can find is for Windows !
Thanks !
It sounds like what you want is Ruby's source code. Go to https://www.ruby-lang.org/en/downloads/ and look under "Compiling Ruby - Source Code". That's where you'll find the .tar.gz files you want. You'll need to compile and install it before you can actually use it. Installing normally copies files "all over the file system", but you can force it to install to a specific folder by passing the --prefix option to the ./configure script.
$ tar -xf ruby-2.2.1.tar.gz
$ cd ruby-2.2.1
$ ./configure --prefix=/my/ruby/dir
$ make && make install
You may need to install some dev packages in order to get it to compile, but any compilation errors should make it clear what you need.
These instructions are also described here.
Thank you Max for your response.
In case someone else tries to compile ruby on a fresh new ubuntu, this is what I had to do to build and use it with success :
Install missing dependencies :
get the latest "Stable Snapshot" from https://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz and not the "Current stable"
sudo apt-get install libffi-dev
sudo apt-get install zlibc zlib1g zlib1g-dev
sudo apt-get install openssl
sudo apt-get install libssl0.9.8 [[[ first, find the latest version with : apt-cache search libssl | grep SSL ]]]
sudo apt-get install ca-certificates
sudo apt-get install libssl-dev
sudo apt-get install libreadline-dev
Then :
Edit downloaded file tools/rbinstall.rb, goto line 714 and correct the typo :
change "rescue LoadErroe" to "rescue LoadError" (not corrected in date of 20 March 2015).
Run Max's instructions above
Don't move the ruby destination folder declared with "--prefix" (even if you try to correct the shells in ruby/bin)
Finally, for using rails :
sudo apt-get install libsqlite3-dev
sudo apt-get install nodejs ==> inorder to have a js runtime
I'm trying to install osm2pgsql from source on a Mac using Terminal.
I ran these commands:
git clone git://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
./autogen.sh && ./configure && make
And it runs, but then if I try to run an osm2pgsql command, it says:
-bash: osm2pgsql: command not found
There are no further instructions online about how to install from source, so I'm not sure what I'm missing here.
Anyone help me?
Thanks
You might need to install the build-essential and automake packages.
Type the following in the terminal (before trying to install osm2pgsql):
sudo apt-get install build-essential
sudo apt-get install automake
sudo apt-get install checkinstall
You need to add it to your path! To "install" something is really just to let the OS know where it is, because it's too dumb to figure that out on its own, even if you're in the same directory with it. In Unix, every command is a program; when you enter a command, the OS checks the "path" which is just a list of directories where that command might live.
First of all, to test that it's compiled and working properly in its own directory:
./osm2pgsql
If that works, add the current directory to the path variable:
export PATH=$PATH:`pwd`
Now you can execute the command from anywhere.