terminal on ubuntu can not open - linux

I uninstalled accidentally python3.10 using rm -rf python3.10 in /usr/bin my terminal is not working anymore
but can access through VSCode but it say
any suggestion? thank you in advanced

It is because /usr/bin/python3 is a soft link to /usr/bin/python3.10 which is the main binary that runs python3 on your machine.
This should help :
$ ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 10 May 31 13:02 /usr/bin/python3 -> python3.10
You might need to install python again to get the binary.
If you have different version of python available that you want to use, create link to it like this:
ln -s file1 link1
which would be in case you have python3.10 re/installed
ln -s /usr/bin/python3.10 /usr/bin/python3
Considering you deleted python3.10 binary by mistake!

Related

How to add a Path to update-alternatives --config php

I'm working on a Ubuntu 16 machine:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
My experience with Ubuntu is "medium".
I needed to change the path the php command refers to in alternatives.
I did the following:
cd /etc/alternatives
ls -ls | grep php
0 lrwxrwxrwx 1 root root 15 Mar 7 06:31 php -> /usr/bin/php7.0
I want to change the path /usr/bin/php7.0 to /opt/plesk/php/7.2/bin/php.
The first thing I tried is update-alternatives --config php.
This gave me this:
There is 1 choice for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/php7.0 70 auto mode
* 1 /usr/bin/php7.0 70 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Sadly, I can't add another path by using this command.
The second thing I tried to do is this: update-alternatives --set php /opt/plesk/php/7.2/bin/php. The result of that:
update-alternatives: error: alternative /opt/plesk/php/7.2/bin/php for php not registered; not setting
The third attempt, I went to /etc/alternatives and used unlink php. Then I created a new symlink like this: ln -s /opt/plesk/php/7.2/bin/php php.
This changed the path in alternatives indead. See for yourself:
root#xxtweb03:/etc/alternatives# ls -ls | grep php
0 lrwxrwxrwx 1 root root 26 Apr 4 12:18 php -> /opt/plesk/php/7.2/bin/php
It has only one disadvantage.
When I run this command: update-alternatives --config php then the /opt/plesk/php/7.2/bin/php is not among the selection.
This is what I get:
root#xxtweb03:/# update-alternatives --config php
There is 1 choice for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/php7.0 70 auto mode
1 /usr/bin/php7.0 70 manual mode
Question: how can I add /opt/plesk/php/7.2/bin/php to the Path list that is displayed when running update-alternatives --config php?
you have to install alternative path first to display it in alternatives list,
see manual page
by using this command,
update-alternatives --install /usr/bin/php php /opt/plesk/php/7.2/bin/php 71
it will install your /opt/plesk/php/7.2/bin/php into alternatives list
I had to append an additional and mandatory option priority. The value has to be an integer.
This worked for me:
sudo update-alternatives --install /usr/bin/php php /opt/plesk/php/7.2/bin/php 100
Maybe you also want to add alternatives of these commands:
phar
phar.phar
php-cgi
php-cgi-bin
These commands will add alternatives for all five commands (also called link groups):
sudo update-alternatives --install /usr/bin/php php /opt/plesk/php/7.2/bin/php 100
sudo update-alternatives --install /usr/bin/phar phar /opt/plesk/php/7.2/bin/phar 100
sudo update-alternatives --install /usr/bin/phar.phar phar.phar /opt/plesk/php/7.2/bin/phar.phar 100
sudo update-alternatives --install /usr/bin/php-cgi php-cgi /opt/plesk/php/7.2/bin/php-cgi 100
sudo update-alternatives --install /usr/lib/cgi-bin/php php-cgi-bin /opt/plesk/php/7.2/bin/php-cgi 100

How do I alias python2 to python3 in a docker container?

I am trying to set the default python in my docker container to be python3 and have set the aliases in the dockerfile. When I open the .bashrc file, they show up. As far as I can tell, it should work but the default python version is still 2.7. if I run which python, it will still point to usr/bin/python rather than python3. Same with pip. Can anyone tell me what the problem is? Here is the command I'm using to alias:
RUN \
echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc
Does this look right? I am using ubuntu 17.10
You try to create a symlink for python bin
RUN ln -s /usr/bin/python3 /usr/bin/python & \
ln -s /usr/bin/pip3 /usr/bin/pip
other option is use update-alternatives for more visit this site
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3
and another option is trying source the bashrc file after updating
RUN \
echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc && \
source /root/.bashrc
I recommend seeing all options of python images on Docker Hub
Tip: use anaconda or conda for managing your python versions (conda site)
The answer above is great, except it should be as follows:
RUN ln -s /usr/bin/python3 /usr/bin/python && \
ln -s /usr/bin/pip3 /usr/bin/pip
Perhaps they typo-ed by writing ls which just lists the contents of the directory, rather than using ln which actually creates symlinks.

Bash: No such file or directory?

I try to use an executable script (wkhtmltopdf) on a Linux shared webserver (Debian, 64bit). I am pretty sure that I compiled everything correct, but whenever I want to execute the file I get as an response :
> ./wkhtmltopdf -H
-bash: ./wkhtmltopdf: No such file or directory
To be sure that the file is there, here the ls output :
> ls
wkhtmltoimage wkhtmltopdf
Furthermore I tested the file command on it, which outputs the following :
> file wkhtmltopdf
wkhtmltopdf: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
My question is now :
Why does bash tells me that there is no 'file or directory', when there obviously is one?
My first guess would be that the shared server does not allow to execute binary files? But shouldn't it then be a problem of permissions, with a different bash output?
Edit :
> id
uid=2725674(p8907906) gid=600(ftpusers) groups=600(ftpusers)
> ls -l wkhtmltopdf
-rwxrwxrwx 1 p8907906 ftpusers 39745960 Jan 20 09:33 wkhtmltopdf
> ls -ld
drwx---r-x 2 p8907906 ftpusers 44 Jan 28 21:02 .
I bet you miss dynamic linker. Just do a
readelf --all ./wkhtmltopdf | grep interpreter
You should get an output like this:
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
There are high chances that you system lacks the interpreter (/lib64/ld-linux-x86-64.so.2 in the example). In this case bash would yell No such file or directory, just like when the binary itself is missing.
You can try to use a different linker. Sometime you can succeed. Just do a:
/path/to/the/linker /path/to/your/executable
This command:
find /lib* -name ld-linux\*
will help you find the linkers on your system. Or you can do the readelf command on some command that does run. It will show you correct, working linker.
OR, since you are running Debian system, just do a
sudo apt-get install wkhtmltopdf
to install native version of the tool :)
In my case
$ readelf --all ./wkhtmltopdf | grep interpreter # readelf: Displays information about ELF files.
[Requesting program interpreter: /lib/ld-linux.so.2]
On a machine where the executable was working:
$ ls -lah /lib/ld-linux.so.2
lrwxrwxrwx 1 root root 25 Apr 16 2018 /lib/ld-linux.so.2 -> i386-linux-gnu/ld-2.27.so
$ dpkg -S /lib/ld-linux.so.2 # -S, --search filename-search-pattern: Search for a filename from installed packages.
libc6:i386: /lib/ld-linux.so.2
So to fix the problem (reference)
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 # GNU C Library: Shared libraries (from apt show)
Missing the linker was my case as well. I could fix it with the help of nsilent22 answer like this:
readelf --all /usr/local/myprogram | grep interpreter
[Requesting program interpreter: /lib64/ld-lsb-x86-64.so.3]
But that linker did not exist anymore.
The old situation in /lib64 was:
ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
ld-linux-x86-64.so.3 -> ld-linux-x86-64.so.2
So it turned out this was just a symlink to the systems' linker.
Moving over to /lib64 , which itself is a symlink to usr/lib64 and creating a symlink over there did not work. I assume that there are to many symbolic link levels after Debian moved everything into /usr
However creating a 'direct' symlink
ln -s /usr/lib64/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3
did the job; /usr/lib64 now shows:
ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
ld-lsb-x86-64.so.3 -> /usr/lib64/ld-linux-x86-64.so.2
I ran into this issue on my raspberry pi 4 running aarch64 alpine 3.13. Using the answer provided by #vkersten, I was able to determine that I was missing /lib/ld-linux-aarch64.so.1.
I resolved this by installing gcompat with apk add gcompat.

how to install nodejs 0.10.26 from binaries in Ubuntu

I am new to linux and am trying to install nodejs latest version with binaries. The solutions I have looked up suggest the installation using apt-get on some private repositories(PPA), which I do not want to do.
So I ran the following commands:
wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-x64.tar.gz
tar -zxvf node-v0.10.26-linux-x64.tar.gz
mv node-v0.10.26-linux-x64 node-v0.10.26
sudo cp -r node-v0.10.26 /usr/local/src
After this, I don't really know what to do. I read an article which suggested created symbolic links, which I am kind of scared to mess up with without knowing the details.
Could you please give me a set of commands to run after this in order to install node with npm? I guess npm should be a part of this binary version.
The best way to install Node.js and have the latest version (or any other version that you prefer, be it LTS or "current") is to download the official binary bundle and uncompress it. A neat way to do it:
# Use version 0.10.26
$ NODE_VERSION="v0.10.26"
# To use a newer version, for example 6.10.3, use instead:
$ NODE_VERSION="v6.10.3"
$ curl -LO http://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.gz
$ tar xzf node-$NODE_VERSION-linux-x64.tar.gz
$ sudo cp -rp node-$NODE_VERSION-linux-x64 /usr/local/
$ sudo ln -s /usr/local/node-$NODE_VERSION-linux-x64 /usr/local/node
The basic idea is to move all the contents of the archive into /usr/local, then create a symlink in /usr/local/node pointing to the most recent version.
For enabling the use of the "node" executable from the command line without referencing the full path (/usr/local/node/bin/node), add /usr/local/node/bin to your $PATH (usually this involves altering the ~/.bash_profile or ~/.profile file; there's plenty of docs for how to do this).
If you need to update Node.js (suppose it's version 7.10.0), then, just extract the tarball in /usr/local and update the symbolic link so it points to the new one. You can then optionally remove the old folder.
May 2017 update
As of the "Creators Update", the commands above can now work also on Windows 10 using the "Windows Subsystem for Linux" (via bash). On Ubuntu on Windows 10, after creating the symlink like above, to add the folder to your $PATH add PATH="/usr/local/node/bin:$PATH" in the ~/.bashrc file.
I combined both of these answers for my docker container. I wanted the executable to be in the PATH already without me explicitly doing that.
#!/usr/bin/env bash
install_node() {
NODE_VERSION="v8.3.0"
curl -# "http://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64.tar.gz" | tar -xz
cp -pr "node-${NODE_VERSION}-linux-x64" "/usr/local/"
ln -s "/usr/local/node-${NODE_VERSION}-linux-x64" "/usr/local/node"
ln -s /usr/local/node/bin/* "/usr/local/bin"
rm -rf "node-${NODE_VERSION}-linux-x64"
}
install_node
You can extract the binary anywhere and use update-alternatives command which maintain symbolic links determining default commands for example this is on my laptop.
first i extract my node node-v10.16.3-linux-x64.tar.xz on /mnt/e/WSL_Ubuntu/Downloads/node-v10.16.3-linux-x64/ folder :
xxxx#xxxxPC:.../WSL_Ubuntu/Downloads$ tar xvf node-v10.16.3-linux-x64.tar.xz
xxxx#xxxxPC:.../WSL_Ubuntu/Downloads$ cd node-v10.16.3-linux-x64/
then update-alternatives --install :
xxxx#xxxxPC:.../node-v10.16.3-linux-x64/bin$ sudo update-alternatives --install /home/wira/.local/bin/node node\
> /mnt/e/WSL_Ubuntu/Downloads/node-v10.16.3-linux-x64/bin/node 60
update-alternatives: using /mnt/e/WSL_Ubuntu/Downloads/node-v10.16.3-linux-x64/bin/node to provide /home/wira/.local/bin/node (node) in auto mode
Now i use the node on terminal
xxxx#xxxxPC:.../node-v10.16.3-linux-x64/bin$ node --version
v10.16.3
You should also update-alternatives --install on npm binaries.
I think there is still a cleaner way
NODE_VERSION="v6.7.0"
# Download
curl -LO http://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.gz
# uncompress
tar xzf node-$NODE_VERSION-linux-x64.tar.gz
# selective copy
cp -R ./node-$NODE_VERSION-linux-x64/bin/* /usr/local/bin
cp -R ./node-$NODE_VERSION-linux-x64/lib/* /usr/local/lib
cp -R ./node-$NODE_VERSION-linux-x64/include/* /usr/local/include
cp -R ./node-$NODE_VERSION-linux-x64/share/* /usr/local/share
Node should be working now
$ node -e 'console.log("HI")'
HI
Hope it helps

How can I check if ncurses is installed?

How can I check if ncurses is installed in a Red-Hat Linux OS? One solution is to use
dpkg -l '*ncurses*' | grep '^ii'
But I don't even have the dpkg package in my system, and since I don't have the administrative rights, I can't install it.
On RedHat based systems there is (mostly) no dpkg but you can use rpm -qa | grep ncurse
on mac:
prompt> ls -la /usr/include/ncurses.h
lrwxr-xr-x 1 root wheel 8 11 jul 14:24 /usr/include/ncurses.h -> curses.h
The second line being not empty, this means ncurses is installed.

Resources