Tag Archives: linux

curl_openssl_4_not_found

Dynamic Linking Error: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_4′ not found

  1. Why is this happening?
  2. Am I in the same situation?
  3. The Million $ Solution

Why is this happening?

Well, if you end up on this page, you for sure are in a bad situation.

It took me some good hours to debug and solve this problem but maybe you can close this chapter much faster. You are encountering this issue because a native module that you are using depends on CURL_OPENSSL_4.

Am I in the same situation?

There are multiple reasons why you may encounter this error: CURL_OPENSSL_4 not found.

The most common ones are:

  1. Symbolic Link from /usr/lib/x86_64-linux-gnu/libcurl.so.4 -> /usr/lib/x86_64-linux-gnu/libcurl.so.4.X.X is bad. You might need to recreate it.
  2. libcurl version is not installed -> Easy fix -> install it
  3. libcurl version is wrong -> This is what we’re gonna cover

If you are a Linux user who is also into system level software development, you may find yourself in situations where-in you need information related to symbols in an object file. You’ll be glad to know there exists a command line utility – nm – that you can use in these situations.

The nm command line utility basically lists symbols from object files. Here’s the tool’s syntax:

nm [OPTIONS] OBJECT-FILENAME

Run:

nm -D /usr/lib/x86_64-linux-gnu/libcurl.so.4|grep CURL

What you should see is:

0000000000000000 A CURL_OPENSSL_4

What you might see:

0000000000000000 A CURL_OPENSSL_3

Well clearly things don’t look good. Your Linux distribution is built using other libcurl version. You may attempt to uninstall it and add another version but it might break apt.

The Million $ Solution

I switched to a Linux distribution that includes libcurl4.

I was using node-12-slim which is built on Debian-Stretch. You cannot install libcurl4 on this version since it’s built on CURL_OPENSSL_3.

I switched to node-12-buster-slim which is built on top of Debian-Buster and installed libcurl4 and things started working.

apt-get install libcurl4 -y

That’s all 🙂

How to run Git pull in all subdirectories

Git pull allows you to retrieve the latest changes from the remote repository.

If you ever need to run git pull in all subdirectories but you don’t want to manually do it for each of them, you create a bash script as follows:

#! /usr/bin/env bash
for dir in ./*/
do
    cd ${dir}
    git status >/dev/null 2>&1
    # check if exit status of above was 0, indicating we're in a git repo
    [ $(echo $?) -eq 0 ] && echo "Updating ${dir%*/}..." && git pull
    cd ..
done

Set the permissions:

chmod +x git-pull.sh

And run ./git-pull.sh

Source

OSX Global NPM Module command not found

In case you ended up in a situation where you just installed a global NPM module, but it still throws command not found, here’s what you have to do:

Find out where the global NPM modules are installed by running:

npm prefix -g

Double check that your $PATH does not already contain that value:

echo $PATH

If the value is not included, you must update your etc/paths with the NPM location:

sudo vi /etc/paths

Add the value returned by npm prefix -g preceded by /bin

e.g. /Users/catalinmunteanu/.npm-global/bin

Save the file and exit.

Open a new terminal tab/window and retry the command.

Cheers!

Node n permission denied without sudo

Each time I do a fresh install of the Node Version Management tj/n I end up getting the permission denied when running npm install.

If you also ran into this issue, well, there’s a quick fix.

The issue is caused by the Node Version Management for which the owner is the root.

The two following steps will help you continue in peace 😀

which n

Returns the install location of the Node Version Management package. e.g. /Users/username/n

sudo chown -R $(whoami) <PATH_WHICH_N>

Sets the current user as owner.

You can now install the NPM packages without the power of sudo.

Docker Tutorial – Getting started with Docker

This Docker Tutorial should help you get started with Docker.

  1. How to get a running Docker Machine on your computer
  2. How to create and manage Docker Images
  3. How to create and manage Docker containers
  4. How to delete Docker images and containers
  5. How to login to Docker Hub
  6. How to publish images to Docker Hub

You’ll learn how to start a Docker Machine on your PC, how to create images, how to create containers, and to cleanup your Docker Machine, login to Docker Hub, tag and publish images.

1. How to get a running Docker Machine on your computer

First thing you need to do before starting to manage images and containers is to have a Docker Machine up and running. For this tutorial I’m using Virtual Box for running the Docker Machine.

The next command creates a Docker Machine named dev. The command will check and download the required dependencies, create the VM, create a SSH key, start the VM and assign an IP and generate certificates.

docker-machine create --driver virtualbox dev

Running the above command is only needed the first time you create a Docker Machine. When you just need to start it you must run:

docker-machine start dev

After you have the Docker Machine running, you’ll be able to see the PORT and IP by running the next command. The printed result also contains a short command that you must run in order to set Docker Machine configuration in your environment.

docker-machine env dev

You must now set the environment with the Docker Machine configuration for the current terminal session by running:

eval $(docker-machine env dev)

That’s all for the first step. Starting a Docker Machine is quite easy.

In case you’re getting an IP allocation error, check out this article. It might help.

2. How to create and manage Docker Images

Now that we have the machine up and running we can list all the available images with:

docker images

In order to create a new image we must have a Dockerfile. I won’t get into how to create Dockerfile in this article but I’ll continue the tutorial using a base Nginx Dockerfile. Place this content in a file named Dockerfile

FROM nginx:latest
RUN nginx -v
EXPOSE 80
CMD ["bash", "-c", "nginx -g 'daemon off;'"]

Now you have a base Dockerfile and you can create an image from it by running:

docker build -t the_tag .

This command also requires that you have the Dockerfile in cwd. The dot from the end specifies that you are using a Dockerfile from the local directory. You can also build using a Dockerfile that’s not in the cwd by specifying the path to the Dockerfile:

docker build -f Dockerfile -t the_tag .

For both of the above commands you’ll see the following steps being executed:

Sending build context to Docker daemon 338.1MB
Step 1/4 : FROM nginx:latest
 ---> f68d6e55e065
Step 2/4 : RUN nginx -v
 ---> Using cache
 ---> 46c77d837d51
Step 3/4 : EXPOSE 80
 ---> Using cache
 ---> b31d714e67f1
Step 4/4 : CMD ["bash", "-c", "nginx -g 'daemon off;'"]
 ---> Using cache
 ---> c3f3bfb92c45
Successfully built c3f3bfb92c45
Successfully tagged the_tag:latest

If something goes wrong in any step the build will fail and the error will be printed. If you now run docker images again you’ll see:

REPOSITORY       TAG           IMAGE ID          CREATED             SIZE
the_tag          latest        c3f3bfb92c45      7 minutes ago       109MB

3. How to create and manage Docker containers

We now have a Docker image created and we’re ready to create and manage containers. You can list all available containers by running:

docker ps

Create a new container using the image we built by running:

docker run -d --name docker-nginx -p 80:80 the_tag

-d flag causes the container to run in detached mode
–name allows you to easily identify the container by setting a label
-p allows you to set publish the HOST:CONTAINER ports.

If you now run docker ps you’ll see something like this:

CONTAINER ID    IMAGE        COMMAND     CREATED          STATUS          PORTS                NAMES
c2e1bdcf12a0    image_tag    "bash -c"   3 seconds ago    Up 2 seconds    0.0.0.0:80->80/tcp   docker-nginx

You may now stop and delete this container by running:

docker stop c2e1bdcf12a0
docker rm c2e1bdcf12a0

4. How to delete Docker images and containers

In some articles I previously wrote I described how to keep your Docker Machine clean and how to delete certain images and containers or do a full cleanup.

Check out this article if you’re on OSX/Linux.

Check out this article if you’re using Windows.

5. How to login to Docker Hub

If you plan to publish your images to Docker Hub you’ll probably need to login.

docker login --username username@example.com --password THE_PASSWORD docker-hub.example.com:PORT

Be careful to specify the PORT. If you don’t, the authentication will work but publishing images will not find a token for the host.

6. How to publish images to Docker Hub

You’re now have an image and are authenticated to your Docker Hub. You can publish the image and make it available for others to use as well.

docker images # prints the hash
docker tag HASH docker-hub.example.com:443/<IMAGE_REPOSITORY_NAME>:0.0.1
docker push docker-hub.example.com:443/<IMAGE_REPOSITORY_NAME>

That’s it. The image is now on the hub.

NPM module command not found

Until you properly config your environment you’ll probably run into the command not found error when trying to run globally installed NPM modules.

Solution for Linux and OSX:

Step 1 – check if the path is correct

You need to have /users/<ME>/.npm-global/bin in your $PATH

echo $PATH

If the printed string doesn’t contain the above path, continue to Step 2

Step 2 – add npm global install path

We need to adjust the $PATH in order to contain the path to the NPM global module folder:

export PATH=$PATH:~/.npm-global/bin

Step 3 – reload .bashrc

The .bashrc file is usually only reloaded on startup. Run the bellow command to reload it again after you made the changes from Step 2.

source ~/.bash_profile

That’s all. Your global NPM modules should now work in your terminal.

How to clear Docker Machine on Linux

A few intensive hours building Docker containers quickly used up all the allocated space.

Deleting Docker images can be done using -f to force deletion of images that are used in other containers that remain.

docker images docker rmi <IMAGE_ID> -f 

Deleting Docker containers:

docker ps docker rm <CONTAINER_ID> 

Easy right?

What if you got tens of images? Still easy.

There are multiple ways of deleting Docker images depending on how they’re used.

The dangling images are not tagged and not used by any container. You can remove these images using (-f flag confirms the operation):

docker image prune -f

If you instead want to remove all images that are not referred in any container:

docker image prune -a

Cleaning containers is an easy task. You can clear only containers that are not running. The following command will stop all running containers:

docker container stop $(docker container ls -aq)

Now that we don’t have any running containers we can completely remove them using:

docker container rm $(docker container ls -aq)

Check this post and learn how to quickly delete Docker containers and images if you’re running on Windows.

Useful Linux Commands

List processes sorted by memory usage:

ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS

Check which process uses an input port:

sudo netstat -tulpn | grep :input_port

Output the md5 of each file to the defined filename:

find * -type f -exec /usr/bin/md5sum {} + > output_filename

View opened file descriptors by pid:

lsof || /usr/sbin/lsof -P -n -p input_pid