Can one just copy perl modules from one Linux machine to another? - linux

I have a remote CentOS server (Release 6.10) set up by someone else. I have quite a few perl modules installed on the machine.
I have set up a local CentOS server (Release 7.7.1908). I would like to have the EXACT same set of perl modules on my local machine. Installing them one by one via cpan is an option but I can run into issues as some of the perl modules are older (very) versions.
I was wondering, if I can copy modules from the remote server to my local server. Can I do that? Are there other options?

It's not safe to copy modules from one machine to another because things may not be set up identically. It's best to reinstall them.
You can use the autobundle command in the cpan shell to create a dump of all the modules you have installed on the old machine. You can then use that dump to tell the cpan shell on the new machine what modules to install.
Thanks to Polar Bear, here's a link to an article that explains how to reinstall the autobundle.

The solution suggested by Andy Lester is perhaps the best way to do it. I found a documentation here in addition to ones suggested.
In my case however this was not straight forward because the source server environment is very old and there were many dependencies that I will need to manually resolve. In general if you have similar environments and clean installs, the auto bundle approach will make it easy.

Related

Perl 5.10 with Spreadsheet-ParseXLSX-0.17?

Hi I sit behind a firewall at work unable to get a direct route to the internet but wanting to install a version of Perl for Linux that comes with, or is capable of being made to run Spreadsheet-ParseXLSX.
I am modifying a program that uses Spreadsheet-ParseExcel to work with xlsx files but an new to perl installations and only have user access.
Help would be appreciated.
In general you can get along fine by copying the perl modules from a distribution into a directory of your choice on the server, adding said directory to the PERL5LIB environment variable. Observe the local directory structure the distribution defines for its files. In the case of Spreadsheet::Parse, that would be:
_your dir_
Spreadsheet
ParseExcel
...(lots of stuff)...
WriteExcel
...(lots of stuff)...
XLSX
Fmt2007.pm
Utility2007.pm
ParseExcel.pm
WriteExcel.pm
XLSX.pm
Offhand I don't remember any dependencies that aren't satisfied by the core modules of 5.10 - however, if there are some, your perl will tell you ;-).
A slightly more robust method is to install the modules on a local machine under your control using eg. the CPAN module and copy the files from the build subdirectory or the site_perl subdirectory of your perl installation.
Caveat
This practice will only work reliably with pure perl modules !
It will always be better to address the sys admin people and ask them nicely to install the needed modules!

How to automake installation process on Linux-like operating systems?

I wrote a simple C application but it has some dependencies. Instead of giving my friend (who is a linux noob) commands to run in terminal, to install the dependencies, I would like to give him a single file that would install everything my application needs.
Btw, is makefile a good idea, or maybe a bash script would be most appropriate? I would like to ask about the root password only once, save it somewhere (in the script/makefile variable) and then simply use it to install all dependencies. Any ideas how to do it the most professional way?
This is what packages are for.
Depending on what target OS/distribution, you will need to package a DEB or an RPM.
There are tools to simplify this process that allow declaring dependencies as well as running pre/post install/uninstall scripts.
The most professional way to distribute this is using a private repository.

How to change the perl cpan repository location

When I am using cpan to install module, there is a download source which is very unstable and slow, and I might want to install that module on many machines?
Is that possible to change the perl module repository to other address, or copy the repos to local disk.
Or, can we save the local module files to local when we use cpan. It seems cpan would delete it after installation.
Is that possible to change the perl module repository to other address
You can reconfigure cpan (and change your mirror) by running a CPAN shell:
perl -MCPAN -eshell
and then typing:
o conf init
or copy the repos to local disk.
CPAN Mini is the usual tool for this.
cpanm (called "cpanminus") is a very popular alternative installer for Perl modules. With cpanm, you can use the --mirror option to point it at a different repository URL. I believe cpanm can also create a local cache of all the modules you install, for quicker access later.
Pinto is another option for creating a CPAN-like repository on local disk. However, it aspires to be a more "complete" solution for managing Perl modules. So it might be more than you are looking for.
You could set up a CPAN::Mini repository. You need to install CPAN::Mini, and provide a config file .minicpanrc. Mine is quite short:
# contents of .minicpanrc in home directory
local: /home/ebaudrez/mirrors/minicpan
remote: http://cpan.cu.be/
Obviously, you'll need to tune that to your installation. You can find a list of CPAN mirrors here. Then you have to create the local mirror by calling
minicpan
Beware: the first time, this will take quite some time. Expect a couple of gigabytes of storage to be consumed. Subsequent calls will be much faster. It found it made no sense to call it more than once daily. Also note that only the last release of a distribution is kept, and old or removed distributions will be removed from your local repository.
And then finally, you can tell cpanm to use your mirror preferentially, and to fail back to real CPAN only when the particular distribution or version you're after is not available in your local mirror:
PERL_CPANM_OPT="--mirror $HOME/mirrors/minicpan --mirror http://search.cpan.org/CPAN"
It's possible to configure CPAN or CPANPLUS to use your mirror, too, but I found it slightly less convenient to do so, and prefer cpanminus anyway.
Now you can install any distribution/version you want using cpanm, e.g.,
cpanm Dist::Zilla; # enjoy as the dependencies fly by ;-)
or, say, PDL version 2.006 (note: latest release at the time of writing is 2.007 ;-))
cpanm PDL#2.006 # note: that is new syntax since cpanminus 1.6
Stuff that is in your local mirror will be used if available. Global CPAN will be used for fallback.
I'm surprised nobody has added how to just edit the default CPAN configuration. Using the CPAN shell to do this is just crazy, in comparison to editing a small text file.
Here's how to do it:
Choose some CPAN mirrors from the Official CPAN mirror list.
Locate your CPAN configuration, usually in:
$HOME/.cpan/CPAN/MyConfig.pm
(If not there, then search for the file: MyConfig.pm.)
Edit the list-item called urllist, and add your URLs to it.
'urllist' => [
q[http://httpupdate3.cpanel.net/CPAN/],
q[http://mirrors.servercentral.net/CPAN/],
q[ftp://cpan.cse.msu.edu/]
],

How do I deploy Node.js applications as a single executable file? [duplicate]

This question already has answers here:
How to make exe files from a node.js app?
(20 answers)
Closed 7 years ago.
Supposed I have written a Node.js application, and I now would like to distribute it. Of course, I want to make it easy for the user, hence I do not want him to install Node.js, run npm install and then manually type node app.js.
What I'd prefer was a single executable file, e.g. an .exe file on Windows.
How could I approach this?
I am aware of this thread, anyway this is only about Windows. How could I achieve this in a platform-independent manner? Any ideas? Best practices? ...?
The perfect solution was a "compiler" I can give a source folder to. The source folder contains the app itself in various .js files, the node_modules folder and some metadata, such as the package.json. The output should be binaries for various platforms, such as Windows, OS X and Linux.
Oh, and what's important: I do not want to make any changes to the source code, so calls to require with relative paths should still work, even if this relative path is now inside the packaged app.
Any ideas?
PS: I do not want the user to install Node.js independently, it should be included inside the executable as well.
Meanwhile I have found the (for me) perfect solution: nexe, which creates a single executable from a Node.js application including all of its modules.
It's the next best thing to an ideal solution.
First, we're talking about packaging a Node.js app for workshops, demos, etc. where it can be handy to have an app "just running" without the need for the end user to care about installation and dependencies.
You can try the following setup:
Get your apps source code
npm install all dependencies (via package.json) to the local node_modules directory. It is important to perform this step on each platform you want to support separately, in case of binary dependencies.
Copy the Node.js binary – node.exe on Windows, (probably) /usr/local/bin/node on OS X/Linux to your project's root folder. On OS X/Linux you can find the location of the Node.js binary with which node.
For Windows:
Create a self extracting archive, 7zip_extra supports a way to execute a command right after extraction, see: http://www.msfn.org/board/topic/39048-how-to-make-a-7-zip-switchless-installer/.
For OS X/Linux:
You can use tools like makeself or unzipsfx (I don't know if this is compiled with CHEAP_SFX_AUTORUN defined by default).
These tools will extract the archive to a temporary directory, execute the given command (e.g. node app.js) and remove all files when finished.
Not to beat a dead horse, but the solution you're describing sounds a lot like Node-Webkit.
From the Git Page:
node-webkit is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with node-webkit. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.
These instructions specifically detail the creation of a single file app that a user can execute, and this portion describes the external dependencies.
I'm not sure if it's the exact solution, but it seems pretty close.
Hope it helps!
JXcore will allow you to turn any nodejs application into a single executable, including all dependencies, in either Windows, Linux, or Mac OS X.
Here is a link to the installer:
https://github.com/jxcore/jxcore-release
And here is a link to how to set it up:
http://jxcore.com/turn-node-applications-into-executables/
It is very easy to use and I have tested it in both Windows 8.1 and Ubuntu 14.04.
FYI: JXcore is a fork of NodeJS so it is 100% NodeJS compatible, with some extra features.
In addition to nexe, browserify can be used to bundle up all your dependencies as a single .js file. This does not bundle the actual node executable, just handles the javascript side. It too does not handle native modules. The command line options for pure node compilation would be browserify --output bundle.js --bare --dg false input.js.
There are a number of steps you have to go through to create an installer and it varies for each Operating System. For Example:
on Mac OS X you need to create a .pkg, there are instructions on how to do that here: https://coolaj86.com/articles/how-to-create-an-osx-pkg-installer.html
on Ubuntu Linux you need to create a .deb, there are instruction on how to do that here: https://coolaj86.com/articles/how-to-create-a-debian-installer.html
on Microsoft Windows you need to create a .exe or .msi, there are instruction on how do that using the innosetup installer here: https://coolaj86.com/articles/how-to-create-an-innosetup-installer.html
You could create a git repo and setup a link to the node git repo as a dependency. Then any user who clones the repo could also install node.
#git submodule [--quiet] add [-b branch] [-f|--force]
git submodule add /var/Node-repo.git common
You could easily package a script up to automatically clone the git repo you have hosted somewhere and "install" from one that one script file.
#!/bin/sh
#clone git repo
git clone your-repo.git

Install CPAN Modules without messing up the system Perl installation

I have heard that it is best to not install modules from CPAN where your system's version of Perl is. I know how to install modules using the command line, I was just wondering if there is a way to keep CPAN separate from the system's core Perl.
Should I:
Download the source and make a directory specifically for these modules?
Anybody have any other ideas or implementations they have used successfully?
I am using Arch Linux with Perl 5.16.2.
Are you looking for something like local::lib
local::lib - create and use a local lib/ for perl modules with PERL5LIB
Download and extract the latest version of local::lib:
curl -LO http://search.cpan.org/CPAN/authors/id/A/AP/APEIRON/local-lib-1.008004.tar.gz
tar xzf local-lib-1.008004.tar.gz
cd local-lib-1.008004/
Deploy it:
perl Makefile.PL --bootstrap=$HOME/perl5
make
make test
make install
Save persistent configuration:
cat << PROFILE >> $HOME/.profile
eval \$(perl -I\$HOME/perl5/lib/perl5/ -Mlocal::lib)
PROFILE
Now, you can logoff/logon your session or simply source ~/.profile.
After that steps, CPAN modules will be installed locally.
You don't need to install the module manually. You just need to have somewhere to install it to, and your environment configured to install it there. Then you can use cpan/cpanp/cpanm/etc as normal. (cpan minus wins for me)
Setting up that environment manually is a bit of a pain, so most people use an application to set up the configuration for them.
The two main choices for this are:
local::lib — This sets up your environment variables so you can install modules away from the system perl, but continues to use the system perl.
Perlbrew — this installs a complete perl for you so lets you avoid your system perl entirely, and use a more up to date version of perl itself then might come with your system. It also manages multiple perl installs side by side (so you can test your modules against different versions of perl).
Personally, I prefer Perlbrew (as it makes it easy to play with shiny new features like the yada yada operator and smart match (not that smart match is all that new now) but it takes longer to set up (as you have to compile perl).
I have heard that it is best to not install modules from CPAN where your system's version of Perl is.
The idea is to avoid breaking your distro's tools by upgrading a module they use.
Installing the modules to a fresh directory and telling Perl about it using PERL5LIB (which is what aforementioned install::lib does) is not going to help at all in that case, since Perl sees exactly the same thing as if you had installed the module in the usual site directory.
(One would mainly use PERL5LIB to install modules when one doesn't have permission to install to the default directories.)
The other problem with using the system Perl is that you are prevented from upgrading it.
The solution to both is to install your own build of Perl. This is very easy to do using perlbrew.
What's about cpanminus?
CPAN minus module
Why don't you pack the modules into real packages, rpm or dep style? That way you keep control over the installed software, you can remove and update the packages as required and as you are used to. So instead of bypassing the management, which rarely is a good idea, you stay in control.
If you are using an rpm based distribution I really recommend OBS for this task. You can create your own project, configure sources, test them and have packages created for all sorts of distributions and architectures. And when you import your home projects repository into your software management then installing the packages comes down to a single click.

Resources